发送邮件的地址与smtp发送的邮件不同

时间:2019-08-19 16:58:10

标签: php phpmailer

我正在尝试使用phpmailer发送邮件。邮件已发送,但是我无法更改发件人地址。


try {
    //Server settings
    $mail->SMTPDebug = 2;                                       // Enable verbose debug output
    $mail->isSMTP();                                            // Set mailer to use SMTP
    $mail->Host       = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'abc@gmail.com';                     // SMTP username
    $mail->Password   = '****';                               // SMTP password
    $mail->SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
    $mail->Port       = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('xyz@yahoo.com');
    $mail->addAddress('lmn@gmail.com' );     // Add a recipient
    // $mail->addAddress('ellen@example.com');               // Name is optional
    // $mail->addReplyTo('info@example.com', 'Information');
    // $mail->addCC('cc@example.com');
    // $mail->addBCC('bcc@example.com');

    // Attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->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';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

发送邮件时,发件人地址恰好是abc@gmail.com,即smtp设置中使用的地址,而不是我在mail-> setFrom()中输入的地址。我该如何解决? / p>

1 个答案:

答案 0 :(得分:1)

这是PHPMailer文档中涵盖的一个众所周知的问题-gmail不允许您从任意地址发送邮件,因为它是伪造的。最重要的是,雅虎的DMARC策略设置为“拒绝”,因此,即使gmail允许您从雅虎地址发送邮件,任何接收服务器仍会拒绝该邮件。

所以这里的答案是,不,您不能这样做。如果要从Yahoo地址发送 ,则必须通过Yahoo服务器发送。

相关问题