I tried to send an email with the embedded image but the image is sent as text attachment with the original message content of the image. How to properly embed an image to email? Please advise.
$to = 'example@yahoo.com';
$subject = 'test';
$inline = base64_encode(file_get_contents('d.jpg'));
$sep = 'd.jpg';
$headers = "From: youremail@host.com\r\n";
$headers .= "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/related;boundary=\"d0f4ad49cc20d19bf96d4adf9322d567\""."\r\n" ;
$message = "--d0f4ad49cc20d19bf96d4adf9322d567
Content-type: text/html; charset=utf-8
Content-transfer-encoding: 8bit\r\n
<html>
<head>
<style> p {color:green} </style>
</head>
<body>
A line above
<br>
<img src='cid:PHP-CID-d'>".
'<br>
a line below
</body>
</html>'."\n\n";
$message .= "--d0f4ad49cc20d19bf96d4adf9322d567\r\n
Content-Type: image/jpeg;\r\nname=\"$sep\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-ID: PHP-CID-d\r\n
Content-Disposition: inline;\r\n
filename=$sep; size=" .filesize('d.jpg'). ";\r\n
$inline";
mail($to, $subject, $message, $headers) ;