我使用一个简单的PHPMailer表单来允许我网站的用户通过联系表与我联系。我使用我的Google Apps帐户发送邮件。在脚本中,我将用户提供的电子邮件帐户设置为“发件人地址”。
直到几周前,一切顺利。在Google Apps中,我可以单击答复以将答复发送给与我联系的用户。
但是,最近,在不更改代码的情况下,当我单击答复时,我会向自己发送一封电子邮件。 Google的政策是否有所改变?还是我可能偶然做错了什么?
这是我得到的输出。我使用info@kynero.nl发送和使用jaapklok@gmail.com作为客户帐户。但是,当我打开在info@kynero.nl中收到的邮件并单击答复时,我将电子邮件发送到info@kynero.nl,而不是jaapklok@gmail.com
2019-02-06 20:34:31 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP x38sm6269222edx.24 - gsmtp
2019-02-06 20:34:31 CLIENT -> SERVER: EHLO www.kynero.nl
2019-02-06 20:34:31 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a0b:7280:200:0:4d0:baff:fe00:d8e]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-02-06 20:34:31 CLIENT -> SERVER: STARTTLS
2019-02-06 20:34:31 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2019-02-06 20:34:31 CLIENT -> SERVER: EHLO www.kynero.nl
2019-02-06 20:34:31 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a0b:7280:200:0:4d0:baff:fe00:d8e]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-02-06 20:34:31 CLIENT -> SERVER: AUTH LOGIN
2019-02-06 20:34:31 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2019-02-06 20:34:31 CLIENT -> SERVER: <credentials hidden>
2019-02-06 20:34:31 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-02-06 20:34:31 CLIENT -> SERVER: <credentials hidden>
2019-02-06 20:34:31 SERVER -> CLIENT: 235 2.7.0 Accepted
2019-02-06 20:34:31 CLIENT -> SERVER: MAIL FROM:<jaapklok@gmail.com>
2019-02-06 20:34:31 SERVER -> CLIENT: 250 2.1.0 OK x38sm6269222edx.24 - gsmtp
2019-02-06 20:34:31 CLIENT -> SERVER: RCPT TO:<info@kynero.nl>
2019-02-06 20:34:31 SERVER -> CLIENT: 250 2.1.5 OK x38sm6269222edx.24 - gsmtp
2019-02-06 20:34:31 CLIENT -> SERVER: DATA
2019-02-06 20:34:31 SERVER -> CLIENT: 354 Go ahead x38sm6269222edx.24 - gsmtp
2019-02-06 20:34:31 CLIENT -> SERVER: Date: Wed, 6 Feb 2019 21:34:31 +0100
2019-02-06 20:34:31 CLIENT -> SERVER: To: info@kynero.nl
2019-02-06 20:34:31 CLIENT -> SERVER: From: Jaap Klok <jaapklok@gmail.com>
2019-02-06 20:34:31 CLIENT -> SERVER: Reply-To: Jaap Klok <jaapklok@gmail.com>
2019-02-06 20:34:31 CLIENT -> SERVER: Subject: Aanvraag via Inschrijfformulier op kynero.nl
2019-02-06 20:34:31 CLIENT -> SERVER: Message-ID: <0bYvsZOe3xY7iWVxMyFA2uxOvWVDPpl5CAX58DcXA@www.kynero.nl>
2019-02-06 20:34:31 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2019-02-06 20:34:31 CLIENT -> SERVER: MIME-Version: 1.0
2019-02-06 20:34:31 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-02-06 20:34:31 CLIENT -> SERVER:
2019-02-06 20:34:31 CLIENT -> SERVER: Naam: Jaap Klok <br />
2019-02-06 20:34:31 CLIENT -> SERVER: Inschrijving: Detectie vrijdag 10.00 <br />
2019-02-06 20:34:31 CLIENT -> SERVER: Algemene voorwaarden: Akkoord <br />
2019-02-06 20:34:31 CLIENT -> SERVER: Bericht: Test 3 - 21:36
2019-02-06 20:34:31 CLIENT -> SERVER:
2019-02-06 20:34:31 CLIENT -> SERVER: .
2019-02-06 20:34:32 SERVER -> CLIENT: 250 2.0.0 OK 1549485383 x38sm6269222edx.24 - gsmtp
2019-02-06 20:34:32 CLIENT -> SERVER: QUIT
2019-02-06 20:34:32 SERVER -> CLIENT: 221 2.0.0 closing connection x38sm6269222edx.24 - gsmtp
答案 0 :(得分:1)
Google不允许您从任意地址发送邮件。您只能使用自己的帐户地址或Gmail设置中的预定义别名。如果您尝试执行此操作,那么您将看到的只是将您的帐户地址替换为发件人地址。
通常,尝试执行此操作是错误的方法-这是伪造的,由于SPF失败,这将导致您的邮件被垃圾邮件过滤或退回。正确的方法是使用您自己的地址作为发件人地址,并使用提交者的地址作为回复地址。 The contact form example provided with PHPMailer正是这样做的。重要的一点:
//Use a fixed address in your own domain as the from address
//**DO NOT** use the submitter's address here as it will be forgery
//and will cause your messages to fail SPF checks
$mail->setFrom('from@example.com', 'First Last');
//Send the message to yourself, or whoever should receive contact for submissions
$mail->addAddress('whoto@example.com', 'John Doe');
//Put the submitter's address in a reply-to header
//This will fail if the address provided is invalid,
//in which case we should ignore the whole request
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
$mail->Subject = 'PHPMailer contact form';
//Keep it simple - don't use HTML
$mail->isHTML(false);
//Build a simple message body
$mail->Body = <<<EOT
Email: {$_POST['email']}
Name: {$_POST['name']}
Message: {$_POST['message']}
EOT;