Jump to content

Email attachment


dreamwest

Recommended Posts

Ive been trying to get this email attachment to work but I think one of the headers is wrong. It wont attach the file

 

 

$address = "mail@site.com";
$subject = "Test HTML Message";
$hash = md5(rand().time());
$headers .= "From: yourname <you@youremail.com>\r\nReply-To:  noreply@youremail.com";
$headers .= "\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"bound-{$hash}\" ";

$file = "http://www.site.com/images/funny.jpg";
$attachment = chunk_split(base64_encode(file_get_contents($file)));
$ext = pathinfo($file, PATHINFO_EXTENSION);
$file_base = pathinfo($file, PATHINFO_BASENAME);

$body = "
--bound-{$hash} 
Content-Type: text/html
Content-Transfer-Encoding: 7bit


<h2>Hello from Wizecho!</h2>
<p>This is the actual email you will receive with <b>HTML</b> <i>formatting.</i></p>

--bound-{$hash} 
Content-Type: image/jpeg
name=\"{$file_base}\" 
MIME-Version: 1.0
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

{$attachment}
--bound-{$hash}--
";

if(mail($address,$subject,$body,$headers)){

  echo "Email Sent";

}else{

  echo "Mail not sent";

} 

 

Link to comment
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.