PHPMailer不适用于AddAddress属性集

时间:2011-12-20 12:44:53

标签: php email phpmailer

我正在尝试使用phpMailer创建一个联系表单,然后我就进入了firebug:

NetworkError: 500 Internal Server Error - path/process.php
uncaught exception: [object Object]

每次我试图运行下面的代码。
请注意,如果我删除$mail->AddAddress行,则不再显示错误,这就是为什么我怀疑这一行是原因。 相反,当我删除它时会显示一个新错误:You must provide at least one recipient email address

<?php
$name = $_POST['firstName'];
$email = $_POST['email'];
require("phpmailer.inc.php");
$mail = new PHPMailer(true);
$mail->IsMail();
$mail->From = $email;
$mail->Subject = "subject ";
$mail->Body = "From $name with email: $email";
$mail->WordWrap = 50;
$mail->AddAddress('my_address@gmail.com','my name');
$mail->Send();
?>

谢谢!

1 个答案:

答案 0 :(得分:0)

将其重写为:

<?php
$name = $_POST['firstName'];
$email = $_POST['email'];
require 'phpmailer.inc.php';
try {
    $mail = new PHPMailer(true);
    $mail->IsMail();
    $mail->From = $email;
    $mail->Subject = "subject ";
    $mail->Body = "From $name with email: $email";
    $mail->WordWrap = 50;
    $mail->AddAddress('my_address@gmail.com','my name');
    $mail->Send();
} catch (Exception $e) {
    echo $e->getMessage();
}

你会发现错误