简体   繁体   English

PHP邮件以及如何在邮件功能中嵌入图像

[英]php mail and how to embed image in mail function

I Want to send mail in well-formatted HTML, I have following code. 我想以格式正确的HTML发送邮件,我有以下代码。

$to = abc@gmail.com;
$subject = "New good bye profile claim request";
$from = " xyz@gmail.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: $from";
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Jane!</h1>';
$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</body></html>';
mail($to,$subject,$message,$headers);

But its send mail like this. 但是它这样发送邮件。

<html>
<body>
<h1 style="color:#f40;">Hi Jane!</h1>
<p style="color:#080;font-size:18px;">Will you marry me?</p>
</body>
</html>

And I also want to send the image. 我也想发送图像。

You must send it as text/html . 您必须将其作为text/html发送。 So you first have to extend your headers like this: 因此,您首先必须像这样扩展标题:

$header = "From: $from\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";

Then you must update your mail content replacing \\n or linebreaks with MLml tags <br> or even <p> 然后,您必须更新您的邮件内容,以\\n或换行符替换为MLml标签<br>甚至<p>

Then you also can include image tags having the image you want to show in the email 然后,您还可以在图像标签中包含要在电子邮件中显示的图像

<img src="http://www.yourserver.com/images/image1.jpg">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM