PHP Send email with attachment

Published on Author Code Father

PHP Send email with attachment. How to create PHP based email form with file attachment. Downloads, Email

$to =‘;
$subject = ‘PHP Mail Attachment Test’;
$bound_text = “jimmyP123”;
$bound = “–“.$bound_text.”\r\n”;
$bound_last = “–“.$bound_text.”–\r\n”;
$headers = “From:\r\n”;
$headers .= “MIME-Version: 1.0\r\n”
.”Content-Type: multipart/mixed; boundary=\”$bound_text\””;
$message .= “If you can see this MIME than your client doesn’t accept MIME types!\r\n”
$message .= “Content-Type: text/html; charset=\”iso-8859-1\”\r\n”
.”Content-Transfer-Encoding: 7bit\r\n\r\n”
.”hey my <b>good</b> friend here is a picture of regal beagle\r\n”
$file = file_get_contents(““);
$message .= “Content-Type: image/jpg; name=\”regal_004.jpg\”\r\n”
.”Content-Transfer-Encoding: base64\r\n”
.”Content-disposition: attachment; file=\”regal_004.jpg\”\r\n”

if(mail($to, $subject, $message, $headers))
     echo ‘MAIL SENT’;
} else {
     echo ‘MAIL FAILED’;




Categories PHP