phpmailer - 添加动态`$ mail-> From`值会导致未发送的邮件

时间:2014-08-26 18:14:42

标签: php email phpmailer

我得到"来自"通过使用$email = $_POST['company_email'];在页面加载时填充的表单动态发送电子邮件当我将该变量添加到phpmailer中的行$mail->From时,脚本成功运行,但没有收到邮件。如果我静态输入一个值(例如test@email.com),它就会起作用,而回复电子邮件甚至会显示动态地址。

我已将其缩小到导致问题的$mail->From行。有没有人遇到过这个?

我按原样使用PHPMailer:https://github.com/PHPMailer/PHPMailer

为了测试目的,我把它简化为几乎没有:

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$to = $_POST['send_to'];
$company_name = $_POST['company_name'];
$company_email = $_POST['company_email'];
$email_type = $_POST['email_type'];
$subject = '';

$mail->From = 'from@email.com'; // <-- this is the line that's causing the issue
// when changed to $company_email, no mail is received
$mail->FromName = $company_name;
$mail->addAddress($to);               // Name is optional
$mail->addReplyTo($company_email, $company_name);

$mail->Subject = $subject; //'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

修改 我发现它不喜欢雅虎的电子邮件地址。我留下了同样的电子邮件地址,只更改了#34; yahoo&#34;到&#34;邮件&#34;然后&#34; gmail&#34;它起作用了。服务器是否将雅虎地址视为垃圾邮件?

0 个答案:

没有答案