PHP

SEND EMAIL ATTACHMENT WITH PHP 

(simple examples)

RANDOM BOUNDARY $bound = md5(time());

EMAIL HEADER

01

EMAIL HEADER $head = implode("\r\n", [   "MIME-Version: 1.0",   "Content-Type: multipart/mixed;     boundary=\"$bound\'"' ]);

$body = implode("\r\n", [   "--$bound",   "Content-type: text/html; charset=utf-8",   "", "<p>MAIL MESSAGE</p>"  ]);

EMAIL MESSAGE

02

$file = "pic.jpg"; $body .= implode("\r\n", [   "", "--$boundary",   "Content-Type: application/octet-stream;   name=\"'.basename($file)."\"",   "Content-Transfer-Encoding: base64",   "Content-Disposition: attachment", "",   chunk_split(base64_encode   (file_get_contents($file))),   "--$boundary--" ]);

EMAIL ATTACHMENT

03

echo mail("jon@doe.com", "Subject", $body, $head) ? "OK" : "ERROR" ;

SEND EMAIL

04