PHP邮件程序(邮件正文空)

时间:2013-03-27 12:20:54

标签: php phpmailer

我是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!";
}

我做错了什么?

3 个答案:

答案 0 :(得分:1)

我认为您的preg_replace()存在问题。如果我尝试在我的服务器上运行它,我会收到此警告:

  

警告:preg_replace():编译失败:缺少终止]对于偏移量为3的字符类

您是否尝试过不使用preg_replace()的代码,即只是将$bericht传递给MsgHTML()

答案 1 :(得分:0)

我认为您的代码中存在错误

$bericht .= (my html and php code that format the mail);

应该是

$bericht = 'my html and php code that format the mail';

然后代替此

$body             = $bericht;
$body             = preg_replace('/[\]/','',$body);

更容易做到这一点

$body             = preg_replace('/\[\]/','',$bericht);

答案 2 :(得分:0)

如果没有必要,我误解了为什么你需要用变量做这个INCREMENT。

$bericht .= ...;

是的,那里的引号中的字符串值在哪里?

相关问题