dreamwest Posted December 13, 2010 Share Posted December 13, 2010 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 = "[email protected]"; $subject = "Test HTML Message"; $hash = md5(rand().time()); $headers .= "From: yourname <[email protected]>\r\nReply-To: [email protected]"; $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 https://forums.phpfreaks.com/topic/221475-email-attachment/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.