Jump to content

PHP mail with attachment


grissom

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.