Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.