【发布时间】:2013-03-27 12:20:53
【问题描述】:
我是 PHPMailer 的新手,我想用这个类发送 HTML 邮件。但我收到消息说正文是空的。
这是我的代码:
<?php
$bericht .= 'my html and php code that format the mail';
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = preg_replace('/[\]/','',$bericht);
$mail->SetFrom('email@adres', 'Name');
$address = "email@adres";
$mail->AddAddress($address, "");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
我做错了什么?
【问题讨论】:
-
您是否尝试显示您的
$body以确保它确实包含某些内容?也许之前有问题(例如,在填充$bericht的部分中) -
考虑使用
<?php而不是<?