我正在尝试发送带有图片的电子邮件;我的电子邮件正文是:
<?php
$message = <<< email
<img src="http://planet-earth.bogus.us/icons/secret.pictures.gif">
Dear {$email},
email;
?>
当我收到电子邮件时,我看不到图片。相反,我
见<img src="http://planet-earth.bogus.us/icons/secret.pictures.gif">
。我知道这是因为&lt;&lt;&lt;电子邮件;我怎样才能使用&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;电子邮件?
更新
我正在使用zend-framework。我的代码如下所示:
<?php
$mail = new Zend_Mail();
$mail->setFrom('admin@mysite.com', 'My site');
$mail->addTo($recoveryaccount->username);
$mail->setSubject("Mysite");
include "_email_recover_password.phtml";
$mail->setBodyText($message);
$mail->send();
?>
_include "_email_recover_password.pthml"
<?php
$message = <<< email
<img src="http://picturelocation.picture.gif">
Dear {$account->getUsername()},
Somebody has requested that the password associated with this account be
reset. If you initiated this request, click the below link to complete the process:
http://www.example.com/{$account->getRecovery()}
Thank you!
Mysite
Questions? Contact us at admin@mysite.com
email;
?>
答案 0 :(得分:6)
要回答您的问题,您需要发送将内容类型设置为text\html
的内容标头。没有它,接收客户端会将您的消息视为纯文本。以下代码正确设置内容标头并发送基本HTML消息。
// 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);
答案 1 :(得分:1)
不,这不是因为heredoc。您需要发送格式正确的HTML邮件,而不是。有各种标题和MIME'骨架'结构的东西,你根本就没有发送。
不要试图自己建造一个。使用Swiftmailer或PHPMailer为您完成此操作。
答案 2 :(得分:-1)
我用的是什么,
$from="From: TEST\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1";
mail("TOWHO@TEST.com", $title, $content, $from);