【问题标题】:PHP mailer error: Message body emptyPHP 邮件程序错误:邮件正文为空
【发布时间】:2015-08-07 18:23:07
【问题描述】:

我的网站上有一个(直到昨天)工作表格。该表格会提出一些问题,并根据答案发送一封定制的电子邮件。一切正常,但突然停止工作。这是错误状态:

邮件未发送。邮件程序错误:邮件正文为空

这几个月我什么都没改变。也许是服务器升级? PHP版本升级? WordPress 升级?查找附件中的PHP代码,也许你发现某些“新标准”或PHP版本有问题...

require_once("phpmailer/class.phpmailer.php");

// Recuperación de las variables del formulario

$duracion = $_POST['duracion'];
$idiomas = $_POST['idiomas'];
$provincias = $_POST['provincias'];
$zonas = $_POST['zonas'];
$Nombre = $_POST['Nombre'];
$Empresa = $_POST['Empresa'];
$Telefono = $_POST['Telefono'];
$Email = $_POST['Email'];

$mail = new PHPMailer();
$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "localhost"; // SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'presupuesto@myurl.es'; // SMTP username
$mail->Password = 'freelancer2'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->isHTML(true); // Set email format to HTML
$mail->From     = "presupuesto@myurl.es";
$mail->FromName = 'my web';

//mail

$contenido = $duracion."\n".$idiomas."\n".$provincias."\n".$zonas."\n".$Nombre."\n".$Empresa."\n".$Telefono."\n".$Email;

mail("info@myurl.es","Solicitud de Presupuesto",$contenido,"From:$Email");

// resultado en funcion de la puntuación

if ($duracion == 1 and $idiomas == 1 and $provincias ==1 and $zonas == 0) {

  $mensaje = file_get_contents("http://www.myurl.es/presupuesto/2.htm");

$mail->AddAddress($Email);
    $mail->Subject  = "Presupuesto del video";
    $mail->Body     = $mensaje;

    if(!$mail->Send()) {
        echo 'Message was not sent.';
        echo 'Mailer error: ' . $mail->ErrorInfo;
        die();
    }

  Header("Location: http://www.myurl.es/gracias");


} elseif ($duracion == 1 and $idiomas == 1 and $provincias ==2 and $zonas == 0) {

  $mensaje = file_get_contents("




...and so on! 

【问题讨论】:

    标签: php email phpmailer


    【解决方案1】:

    显而易见的结论是,您从http://www.myurl.es/presupuesto/2.htm 检索的内容是空的,或者有问题。这就是为什么您应该始终检查返回值的原因。

    您还伪造了某些消息的发件人地址,这几乎可以保证传递失败。

    你为什么打电话给mail() 以及使用PHPMailer?

    我还看到你使用的是旧版本的 PHPMailer,所以我建议更新。

    【讨论】:

    • 嗨同步,感谢您的 cmets!为填充消息正文而调用的 URL 可以正常工作且没有问题。该表格还有一个检查器,用于确保所有输入都填写妥当(来自、邮件等)。最奇怪的是,这在周二之前一直运行良好,然后突然停止工作...... :-(((
    • 好的,用一些静态内容试试吧。
    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 2021-01-26
    • 2014-08-07
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多