php send email with image

巧了我就是萌 提交于 2019-12-02 09:39:10

To answer your question, you need to send out content headers that sets the content type to text\html. Without it, your message is treated as plain text by the receiving client. The following code sets the content headers properly and sends out a basic HTML message.

// message
$message = '
<html>
<body>
  <img src="http://planet-earth.bogus.us/icons/secret.pictures.gif">
</body>
</html>
';

// Add the content headers
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: David <david-z@domain.com>' . "\r\n";
$headers .= 'From: Bot <bot@domain.com>' . "\r\n";

mail("david-z@domain.com", "mysubject", $message, $headers);

No, it's not because of the heredoc. You need to send a properly formatted HTML mail, which you aren't. There's various headers and MIME 'skeleton' structural stuff that you're not sending at all.

Don't try to build one yourself. Use Swiftmailer or PHPMailer to do that for you.

Muhamad Nabil

What i use ,

$from="From: TEST\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1"; 
mail("TOWHO@TEST.com", $title, $content, $from); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!