我有一个简单的php电子邮件脚本,我希望在底部包含一个图像。当我添加如下图像标签时,电子邮件只显示<img src="http://domain.com/images/logo.png" />
而不是实际图像。有什么想法吗?
<?PHP
$email = $_POST["emailaddress"];
$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$headers .= "Content-type: text/html\r\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: info@domain.com\n";
$usermessage =
"
Thank you for joining our mailing list.
We hope to see you very soon!
Address 1
Address 2
<img src=\"http://domain.com/images/logo.png\" />
";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
$fh = fopen("email.xml", "a");
fwrite($fh, "$email\r\n");
fclose($fh);
?>
答案 0 :(得分:2)
您没有使用正确的消息传递Content-Type标头。 $headers
确实包含正确的标头,但它是使用纯文本消息发送的,而$userheaders
不包含Content-Type
标头,但与之关联的消息确实包含一些HTML
替换
$userheaders = "From: info@domain.com\n";
与
$userheaders = "From: info@domain.com\r\n";
$userheaders = "Content-type: text/html\r\n";
它应该可以正常工作
答案 1 :(得分:-1)
您需要指定html标头。您可以使用支持发送HTML电子邮件的完善方法,而不是自己动手,例如PHPMailer: