Re: Fwd: E-mail attachments

Gene Clark <[email protected]> Sun, 29 Dec 2013 21:38:58 -0500
Newsgroups gmane.comp.php.drupal.devel
Message-ID <[email protected]>
--Apple-Mail-ECA8CBCE-7699-4D4D-B659-D674F4B1F17C
Content-Type: text/plain;
	charset=us-ascii
Content-Transfer-Encoding: quoted-printable

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



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

I don't see anything obviously wrong in your sample, but after comparing you=
r implementation with mine from a recent project, I see a couple of differen=
ces:

1. You mention using the mimemail module, but are you also using the mailsys=
tem module?  The simplest explanation would be that mimemail is not getting i=
nvoked at all.
2. If I recall correctly, some fields you can set in the "message" array ups=
tream can get unset before hook_mail is called for you.  So you may need to p=
ut these items into your "params" array and hammer them in as part of your h=
ook_mail implementation.  My code looks like this:

Sending the mail:

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

In my hook_mail implementation:

  switch ($key) {
    case 'send-test':
      $message['subject'] =3D $params['subject'];
      $message['body'][] =3D $params['message'];
      $message['headers'] =3D array_merge($message['headers'], $params['head=
ers']);
      break;
  } =20

Note also that I'm setting some parameters that you are not setting ('plain'=
, 'plaintext');  I believe I added those after debugging the problem you're h=
aving here.

Hope this helps,

Rob

Rob Thorne
Torenware Networks



> On Dec 29, 2013, at 12:50 PM, Muzaffer Tolga Ozses <[email protected]> wrote=
:
>=20
> Hi,
>=20
> I keep developing my module, and inside it I am sending e-mail. I am also t=
rying to attach a file, to no avail. I have installed mimemail, I have chang=
ed mime type in my code, I have dpm'd everything. dpm gives me correct value=
s, and the subject and body of the e-mail come through, but I couldn't get f=
ile attachment to work at all. What else can I do?
>=20
> Regards,
>=20
> PS: You can see the code at http://drupalcode.org/sandbox/Kartagis/1543120=
.git/blob/da47378:/pass2pdf.module#l69


--Apple-Mail-ECA8CBCE-7699-4D4D-B659-D674F4B1F17C
Content-Type: text/html;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D=
utf-8"></head><body dir=3D"auto"><div>Shut up I'm sick of your stupid emails=
!!!!<br><br><div style=3D"-webkit-tap-highlight-color: rgba(26, 26, 26, 0.29=
2969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webki=
t-composition-frame-color: rgba(77, 128, 180, 0.230469); font-family: Helvet=
ica; font-size: medium; -webkit-text-size-adjust: auto; "><br></div></div><d=
iv><br>On Dec 29, 2013, at 6:47 PM, Rob Thorne &lt;<a href=3D"mailto:rob@tor=
enware.com">[email protected]</a>&gt; wrote:<br><br></div><div><meta http-eq=
uiv=3D"Content-Type" content=3D"text/html charset=3Diso-8859-1">I don't see a=
nything obviously wrong in your sample, but after comparing your implementat=
ion with mine from a recent project, I see a couple of differences:<div><br>=
</div><div>1. You mention using the mimemail module, but are you also using t=
he mailsystem module? &nbsp;The simplest explanation would be that mimemail i=
s not getting invoked at all.</div><div>2. If I recall correctly, some field=
s you can set in the "message" array upstream can get unset before hook_mail=
 is called for you. &nbsp;So you may need to put these items into your "para=
ms" array and hammer them in as part of your hook_mail implementation. &nbsp=
;My code looks like this:</div><div><br></div><div>Sending the mail:</div><d=
iv><br></div><div><blockquote style=3D"margin: 0 0 0 40px; border: none; pad=
ding: 0px;"><div><div>&nbsp; $mail_params =3D array(</div><div>&nbsp; &nbsp;=
 'subject' =3D&gt; $settings['subject'],</div><div>&nbsp; &nbsp; 'message' =3D=
&gt; $settings['message'],</div><div>&nbsp; &nbsp; 'headers' =3D&gt; array(<=
/div><div>&nbsp; &nbsp; &nbsp; 'Content-Type' =3D&gt; 'text/html; charset=3D=
UTF-8'</div><div>&nbsp; &nbsp; ),</div><div>&nbsp; &nbsp; 'attachments' =3D&=
gt; $attachments,</div><div>&nbsp; &nbsp; 'voter' =3D&gt; $credit_app,</div>=
<div>&nbsp; );</div><div>&nbsp; $mail_params['plain'] =3D FALSE;</div><div>&=
nbsp; $mail_params['plaintext'] =3D $mail_params['message'];</div><div>&nbsp=
; if (!empty($settings['bcc'])) {</div><div>&nbsp; &nbsp; $mail_params['head=
ers']['Bcc'] =3D $settings['bcc'];</div><div>&nbsp; }</div><div>&nbsp;&nbsp;=
</div><div>&nbsp; $message =3D drupal_mail('mymodule', 'send-test', $address=
, $language, $mail_params, $from);</div></div><div><br></div></blockquote></=
div><div>In my hook_mail implementation:</div><div><br></div><div><blockquot=
e style=3D"margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>&nbsp;=
 switch ($key) {</div><div>&nbsp; &nbsp; case 'send-test':</div><div>&nbsp; &=
nbsp; &nbsp; $message['subject'] =3D $params['subject'];</div><div>&nbsp; &n=
bsp; &nbsp; $message['body'][] =3D $params['message'];</div><div>&nbsp; &nbs=
p; &nbsp; $message['headers'] =3D array_merge($message['headers'], $params['=
headers']);</div><div>&nbsp; &nbsp; &nbsp; break;</div><div>&nbsp; } &nbsp;<=
/div></div><div><br></div></blockquote></div><div>Note also that I'm setting=
 some parameters that you are not setting ('plain', 'plaintext'); &nbsp;I be=
lieve I added those after debugging the problem you're having here.</div><di=
v><br></div><div>Hope this helps,</div><div><br></div><div>Rob</div><div><br=
><div>
<div>Rob Thorne</div><div>Torenware Networks</div><div><br></div><br class=3D=
"Apple-interchange-newline">

</div>
<br><div><div>On Dec 29, 2013, at 12:50 PM, Muzaffer Tolga Ozses &lt;<a href=
=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:</div><br class=3D=
"Apple-interchange-newline"><blockquote type=3D"cite"><div dir=3D"ltr"><div c=
lass=3D"gmail_default" style=3D"font-family:courier new,monospace">Hi,<br></=
div><div class=3D"gmail_quote"><div dir=3D"ltr"><div style=3D"font-family:'c=
ourier new',monospace"><br></div><div style=3D"font-family:'courier new',mon=
ospace">

I keep developing my module, and inside it I am sending e-mail. I am also tr=
ying to attach a file, to no avail. I have installed mimemail, I have change=
d mime type in my code, I have dpm'd everything. dpm gives me correct values=
, and the subject and body of the e-mail come through, but I couldn't get fi=
le attachment to work at all. What else can I do?</div>

<div style=3D"font-family:'courier new',monospace"><br></div><div style=3D"f=
ont-family:'courier new',monospace">Regards,</div><div style=3D"font-family:=
'courier new',monospace">
<br></div><div style=3D"font-family:'courier new',monospace">PS: You can see=
 the code at&nbsp;<a href=3D"http://drupalcode.org/sandbox/Kartagis/1543120.=
git/blob/da47378:/pass2pdf.module#l69" target=3D"_blank">http://drupalcode.o=
rg/sandbox/Kartagis/1543120.git/blob/da47378:/pass2pdf.module#l69</a></div>

</div>
</div><br></div>
</blockquote></div><br></div></div></body></html>=

--Apple-Mail-ECA8CBCE-7699-4D4D-B659-D674F4B1F17C--