我发送电子邮件的代码
<?php
$to = '[email protected]';
$subject = 'Website Change Request';
$headers = "From: [email protected] \r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '<img src="../1.jpg">';
$message .= '</body></html>';
echo mail($to, $subject, $message, $headers);
?>
当我在<img src="http://weber-steinach.de/files/339349">
其中放置链接时,效果很好,但是当我在本地服务器中放置文件路径时,我将不会在电子邮件中显示图像。
终于我知道了如何做到这一点。这是我所知道的来源链接
$bound_text = "----*%$!$%*";
$bound = "--".$bound_text."\r\n";
$bound_last = "--".$bound_text."--\r\n";
$headers = "From: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed; boundary=\"$bound_text\""."\r\n" ;
$message = " you may wish to enable your email program to accept HTML \r\n".
$bound;
$message .=
'Content-Type: text/html; charset=UTF-8'."\r\n".
'Content-Transfer-Encoding: 7bit'."\r\n\r\n".
'
<html>
<head>
<style> p {color:green} </style>
</head>
<body>
A line above
<br>
<img src="cid:http://localhost/a/img/1.jpg">
<br>
a line below
</body>
</html>'."\n\n".
$bound;
$file = file_get_contents("http://localhost/a/img/1.jpg");
$message .= "Content-Type: image/jpeg; name=\"http://localhost/a/img/1.jpg\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-ID: <http://localhost/a/img/1.jpg>\r\n"
."\r\n"
.chunk_split(base64_encode($file))
.$bound_last;
echo mail($to, $subject, $message, $headers) ;
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句