FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Re: problem sending attachement with the mail() function
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: problem sending attachement with the mail() function [message #178981] Fri, 31 August 2012 12:38
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 8/31/2012 3:27 AM, anomit wrote:
> Hi all,
>
> I'm trying to send an email from a php script with an attachment. This
> is how I am constructing the message body. The mail is sent to the
> right address but the attachment doesn't appear and instead I get to
> see the entire contents of the $output string in the mail. I'd guess
> I'm going wrong with the message boundaries but some help would be
> appreciated
>
> $random_hash = md5(date('r', time()));
> $subject = "your free pdf is here";
> $headers = "From: no-reply(at)my-domain(dot)com\r\nReply-To: no-
> reply(at)my-domain(dot)com";
> $headers .= "\r\nContent-type: multipart/mixed; boundary=
> \"mailer-boundary-".$random_hash."\"";
> $attachment =
> chunk_split(base64_encode(file_get_contents('file.pdf')));
> //the body of the message with the message boundaries and
> attachment as multipart mime
> $output = "
> --mailer-boundary-$random_hash
> Content-Type: multipart/alternative; boundary='mailer-alt-
> $random_hash'
> --mailer-alt-$random_hash
> Content-Type: text/plain; charset='iso-8859-1'
> Content-Transfer-Encoding: 7bit
>
> Hi $fname!
> Your free pdf is attached with this mail.
>
> --mailer-alt-$random_hash
> Content-Type: text/html; charset='iso-8859-1'
> Content-Transfer-Encoding: 7bit
>
> <b>Hi $fname!</b>
> Your free pdf is attached with this mail.
> --mailer-alt-$random_hash--
>
> --mailer-boundary-$random_hash
> Content-Type: application/pdf; name=\"file.pdf\"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename=\"file.pdf\"
>
> $attachment
> --mailer-boundary-$random_hash--";
> mail($email, $subject, $output, $headers) ;
>
> Thanks,
> Anomit
>

Get phpmailer (http://code.google.com/a/apache-extras.org/p/phpmailer/)
and save yourself a lot of problems. It's much better than mail().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Previous Topic: Re: problem sending attachement with the mail() function
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 22:48:17 GMT 2024

Total time taken to generate the page: 0.03893 seconds