grissom Posted July 20, 2009 Share Posted July 20, 2009 Hello all ! I'm having trouble writing a PHP script to send an email with an attachment. All of the scripts I've found via Google are bug-ridden or at least don't work when I give them a try. In this example I am trying to send a test e-mail with the favicon.ico as an attachment (the icon rests in the same directory as the PHP which is trying to send it. Here is what I have so far : $to = $emailaddress; $subject = "A test email"; $boundary = md5(date('r', time())); // concoct a boundary string from a random md5 hash $headers = "From: info@me.com\r\nReply-To: info@me.com"; $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"" . $boundary . "\""; $attachment = chunk_split(base64_encode(file_get_contents("favicon.ico"))); $output = $boundary; $output .= "Content-Type: multipart/alternative; boundary='" . $boundary. "'" . $boundary; $output .= "Content-Type: text/plain; charset='iso-8859-1' Content-Transfer-Encoding: 7bit Hello World!" . $boundary; $output .= "Content-Type: application/ico; name=favicon.ico Content-Transfer-Encoding: base64 Content-Disposition: attachment" . $attachment . $boundary; mail($to, $subject, $output, $headers); Only problem is when I get the mail there is no message body and no attachment PLEASE HELP Best wishes Link to comment https://forums.phpfreaks.com/topic/166639-php-mail-with-attachment/ Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 Check out the following...it makes sending emails so much easier: http://phpmailer.worxware.com/index.php?pg=phpmailer Link to comment https://forums.phpfreaks.com/topic/166639-php-mail-with-attachment/#findComment-878710 Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2009 Share Posted July 20, 2009 Or PEAR Mail::Mime http://pear.php.net/package/Mail_Mime rather than using all that base_64_encode() and chunk_split() crap. Link to comment https://forums.phpfreaks.com/topic/166639-php-mail-with-attachment/#findComment-878722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.