Re: Fwd: E-mail attachments

Αικατερίνη Κατωπόδη <[email protected]> Mon, 30 Dec 2013 09:10:23 +0200
Newsgroups gmane.comp.php.drupal.devel
Message-ID <[email protected]>
--_a46b6835-311b-431c-a7ab-160addc62fc1_
Content-Type: text/plain; charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

I don't know you ''Sir'' who sent you email?!!!
=20



CC: [email protected]
From: [email protected]
Date: Sun=2C 29 Dec 2013 21:38:58 -0500
To: [email protected]
Subject: Re: [development] Fwd: E-mail attachments


Shut up I'm sick of your stupid emails!!!!





On Dec 29=2C 2013=2C at 6:47 PM=2C Rob Thorne <[email protected]> wrote:


I don't see anything obviously wrong in your sample=2C but after comparing =
your implementation with mine from a recent project=2C I see a couple of di=
fferences:=20


1. You mention using the mimemail module=2C but are you also using the mail=
system module?  The simplest explanation would be that mimemail is not gett=
ing invoked at all.
2. If I recall correctly=2C some fields you can set in the "message" array =
upstream can get unset before hook_mail is called for you.  So you may need=
 to put these items into your "params" array and hammer them in as part of =
your hook_mail implementation.  My code looks like this:


Sending the mail:





  $mail_params =3D array(
    'subject' =3D> $settings['subject']=2C
    'message' =3D> $settings['message']=2C
    'headers' =3D> array(
      'Content-Type' =3D> 'text/html=3B charset=3DUTF-8'
    )=2C
    'attachments' =3D> $attachments=2C
    'voter' =3D> $credit_app=2C
  )=3B
  $mail_params['plain'] =3D FALSE=3B
  $mail_params['plaintext'] =3D $mail_params['message']=3B
  if (!empty($settings['bcc'])) {
    $mail_params['headers']['Bcc'] =3D $settings['bcc']=3B
  }
 =20
  $message =3D drupal_mail('mymodule'=2C 'send-test'=2C $address=2C $langua=
ge=2C $mail_params=2C $from)=3B


In my hook_mail implementation:





  switch ($key) {
    case 'send-test':
      $message['subject'] =3D $params['subject']=3B
      $message['body'][] =3D $params['message']=3B
      $message['headers'] =3D array_merge($message['headers']=2C $params['h=
eaders'])=3B
      break=3B
  } =20


Note also that I'm setting some parameters that you are not setting ('plain=
'=2C 'plaintext')=3B  I believe I added those after debugging the problem y=
ou're having here.


Hope this helps=2C


Rob



Rob Thorne
Torenware Networks




On Dec 29=2C 2013=2C at 12:50 PM=2C Muzaffer Tolga Ozses <[email protected]> =
wrote:


Hi=2C





I keep developing my module=2C and inside it I am sending e-mail. I am also=
 trying to attach a file=2C to no avail. I have installed mimemail=2C I hav=
e changed mime type in my code=2C I have dpm'd everything. dpm gives me cor=
rect values=2C and the subject and body of the e-mail come through=2C but I=
 couldn't get file attachment to work at all. What else can I do?


Regards=2C


PS: You can see the code at http://drupalcode.org/sandbox/Kartagis/1543120.=
git/blob/da47378:/pass2pdf.module#l69

 		 	   		  =

--_a46b6835-311b-431c-a7ab-160addc62fc1_
Content-Type: text/html; charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 12pt=3B
font-family:Calibri
}
--></style></head>
<body class=3D'hmmessage'><div dir=3D'ltr'>I don't know&nbsp=3Byou ''Sir'' =
who sent you email?!!!<BR>&nbsp=3B<BR>
<DIV>
<HR id=3DstopSpelling>
CC: [email protected]<BR>From: [email protected]<BR>Date: Sun=2C =
29 Dec 2013 21:38:58 -0500<BR>To: [email protected]<BR>Subject: Re: [d=
evelopment] Fwd: E-mail attachments<BR><BR>
<DIV>Shut up I'm sick of your stupid emails!!!!<BR><BR>
<DIV style=3D"FONT-FAMILY: Helvetica=3B FONT-SIZE: medium"><BR></DIV></DIV>
<DIV><BR>On Dec 29=2C 2013=2C at 6:47 PM=2C Rob Thorne &lt=3B<A href=3D"mai=
lto:[email protected]">[email protected]</A>&gt=3B wrote:<BR><BR></DIV>
<DIV>I don't see anything obviously wrong in your sample=2C but after compa=
ring your implementation with mine from a recent project=2C I see a couple =
of differences:=20
<DIV><BR></DIV>
<DIV>1. You mention using the mimemail module=2C but are you also using the=
 mailsystem module? &nbsp=3BThe simplest explanation would be that mimemail=
 is not getting invoked at all.</DIV>
<DIV>2. If I recall correctly=2C some fields you can set in the "message" a=
rray upstream can get unset before hook_mail is called for you. &nbsp=3BSo =
you may need to put these items into your "params" array and hammer them in=
 as part of your hook_mail implementation. &nbsp=3BMy code looks like this:=
</DIV>
<DIV><BR></DIV>
<DIV>Sending the mail:</DIV>
<DIV><BR></DIV>
<DIV>
<BLOCKQUOTE style=3D"BORDER-BOTTOM: medium none=3B BORDER-LEFT: medium none=
=3B PADDING-BOTTOM: 0px=3B PADDING-LEFT: 0px=3B PADDING-RIGHT: 0px=3B BORDE=
R-TOP: medium none=3B BORDER-RIGHT: medium none=3B PADDING-TOP: 0px">
<DIV>
<DIV>&nbsp=3B $mail_params =3D array(</DIV>
<DIV>&nbsp=3B &nbsp=3B 'subject' =3D&gt=3B $settings['subject']=2C</DIV>
<DIV>&nbsp=3B &nbsp=3B 'message' =3D&gt=3B $settings['message']=2C</DIV>
<DIV>&nbsp=3B &nbsp=3B 'headers' =3D&gt=3B array(</DIV>
<DIV>&nbsp=3B &nbsp=3B &nbsp=3B 'Content-Type' =3D&gt=3B 'text/html=3B char=
set=3DUTF-8'</DIV>
<DIV>&nbsp=3B &nbsp=3B )=2C</DIV>
<DIV>&nbsp=3B &nbsp=3B 'attachments' =3D&gt=3B $attachments=2C</DIV>
<DIV>&nbsp=3B &nbsp=3B 'voter' =3D&gt=3B $credit_app=2C</DIV>
<DIV>&nbsp=3B )=3B</DIV>
<DIV>&nbsp=3B $mail_params['plain'] =3D FALSE=3B</DIV>
<DIV>&nbsp=3B $mail_params['plaintext'] =3D $mail_params['message']=3B</DIV=
>
<DIV>&nbsp=3B if (!empty($settings['bcc'])) {</DIV>
<DIV>&nbsp=3B &nbsp=3B $mail_params['headers']['Bcc'] =3D $settings['bcc']=
=3B</DIV>
<DIV>&nbsp=3B }</DIV>
<DIV>&nbsp=3B&nbsp=3B</DIV>
<DIV>&nbsp=3B $message =3D drupal_mail('mymodule'=2C 'send-test'=2C $addres=
s=2C $language=2C $mail_params=2C $from)=3B</DIV></DIV>
<DIV><BR></DIV></BLOCKQUOTE></DIV>
<DIV>In my hook_mail implementation:</DIV>
<DIV><BR></DIV>
<DIV>
<BLOCKQUOTE style=3D"BORDER-BOTTOM: medium none=3B BORDER-LEFT: medium none=
=3B PADDING-BOTTOM: 0px=3B PADDING-LEFT: 0px=3B PADDING-RIGHT: 0px=3B BORDE=
R-TOP: medium none=3B BORDER-RIGHT: medium none=3B PADDING-TOP: 0px">
<DIV>
<DIV>&nbsp=3B switch ($key) {</DIV>
<DIV>&nbsp=3B &nbsp=3B case 'send-test':</DIV>
<DIV>&nbsp=3B &nbsp=3B &nbsp=3B $message['subject'] =3D $params['subject']=
=3B</DIV>
<DIV>&nbsp=3B &nbsp=3B &nbsp=3B $message['body'][] =3D $params['message']=
=3B</DIV>
<DIV>&nbsp=3B &nbsp=3B &nbsp=3B $message['headers'] =3D array_merge($messag=
e['headers']=2C $params['headers'])=3B</DIV>
<DIV>&nbsp=3B &nbsp=3B &nbsp=3B break=3B</DIV>
<DIV>&nbsp=3B } &nbsp=3B</DIV></DIV>
<DIV><BR></DIV></BLOCKQUOTE></DIV>
<DIV>Note also that I'm setting some parameters that you are not setting ('=
plain'=2C 'plaintext')=3B &nbsp=3BI believe I added those after debugging t=
he problem you're having here.</DIV>
<DIV><BR></DIV>
<DIV>Hope this helps=2C</DIV>
<DIV><BR></DIV>
<DIV>Rob</DIV>
<DIV><BR>
<DIV>
<DIV>Rob Thorne</DIV>
<DIV>Torenware Networks</DIV>
<DIV><BR></DIV><BR class=3DecxApple-interchange-newline></DIV><BR>
<DIV>
<DIV>On Dec 29=2C 2013=2C at 12:50 PM=2C Muzaffer Tolga Ozses &lt=3B<A href=
=3D"mailto:[email protected]">[email protected]</A>&gt=3B wrote:</DIV><BR class=
=3DecxApple-interchange-newline>
<BLOCKQUOTE>
<DIV dir=3Dltr>
<DIV style=3D"FONT-FAMILY: courier new=2Cmonospace" class=3Decxgmail_defaul=
t>Hi=2C<BR></DIV>
<DIV class=3Decxgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"FONT-FAMILY: 'courier new'=2Cmonospace"><BR></DIV>
<DIV style=3D"FONT-FAMILY: 'courier new'=2Cmonospace">I keep developing my =
module=2C and inside it I am sending e-mail. I am also trying to attach a f=
ile=2C to no avail. I have installed mimemail=2C I have changed mime type i=
n my code=2C I have dpm'd everything. dpm gives me correct values=2C and th=
e subject and body of the e-mail come through=2C but I couldn't get file at=
tachment to work at all. What else can I do?</DIV>
<DIV style=3D"FONT-FAMILY: 'courier new'=2Cmonospace"><BR></DIV>
<DIV style=3D"FONT-FAMILY: 'courier new'=2Cmonospace">Regards=2C</DIV>
<DIV style=3D"FONT-FAMILY: 'courier new'=2Cmonospace"><BR></DIV>
<DIV style=3D"FONT-FAMILY: 'courier new'=2Cmonospace">PS: You can see the c=
ode at&nbsp=3B<A href=3D"http://drupalcode.org/sandbox/Kartagis/1543120.git=
/blob/da47378:/pass2pdf.module#l69" target=3D_blank>http://drupalcode.org/s=
andbox/Kartagis/1543120.git/blob/da47378:/pass2pdf.module#l69</A></DIV></DI=
V></DIV><BR></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></DIV> 		 	   		  </di=
v></body>
</html>=

--_a46b6835-311b-431c-a7ab-160addc62fc1_--