当我仅输入一个电子邮件地址时,邮件就会传递到两个电子邮件地址。为什么?

时间:2019-02-03 18:19:04

标签: php email phpmailer

我正在使用下面的功能将我的电子邮件发送到$email_to。当我运行send_email('myotheremail@email.com', 'Subject', 'Message');时,我将同时收到发给mygmail@email.com以及通过$email_to变量发送的电子邮件。

功能如下:

function send_email($email_to, $subject, $body) {
    $mail = new PHPMailer\PHPMailer\PHPMailer();

    try {
        $mail->SMTPDebug = 2;
        $mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->Username = 'mygmail@gmail.com';
        $mail->Password = 'my app password';
        $mail->Host = 'ssl://smtp.gmail.com:465';

        $mail->setFrom('no-reply@domain.com', 'Mailer');
        $mail->addAddress($email_to, 'Name');

        # $mail->addAttachment('/tmp/image.jpg', 'new.jpg');



        $mail->isHTML(true);
        $mail->Subject = utf8_decode($subject);
        $mail->Body = '<html style="font-family: monospace; font-size: 14px; font-weight: normal; margin: 0; padding: 20px 25px; text-align: left;"><body style="width: 700px; -webkit-text-size-adjust: none;">'.utf8_decode($body).'</body></html>';
        $mail->AltBody = $body;

        $mail->send();
        echo 'ok|';


    } catch (Exception $e) {
        echo 'error:'.$mail->ErrorInfo.'|';
    }
}

这是调试日志:

2019-02-03 18:16:24 SERVER -&gt; CLIENT: 220 smtp.gmail.com ESMTP b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:24 CLIENT -&gt; SERVER: EHLO 192.168.1.182<br>
2019-02-03 18:16:24 SERVER -&gt; CLIENT: 250-smtp.gmail.com at your service, [185.65.135.183]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2019-02-03 18:16:24 CLIENT -&gt; SERVER: AUTH LOGIN<br>
2019-02-03 18:16:24 SERVER -&gt; CLIENT: 334 VXNlcm5hbWU6<br>
2019-02-03 18:16:24 CLIENT -&gt; SERVER: &lt;credentials hidden&gt;<br>
2019-02-03 18:16:24 SERVER -&gt; CLIENT: 334 UGFzc3dvcmQ6<br>
2019-02-03 18:16:24 CLIENT -&gt; SERVER: &lt;credentials hidden&gt;<br>
2019-02-03 18:16:25 SERVER -&gt; CLIENT: 235 2.7.0 Accepted<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: MAIL FROM:&lt;no-reply@domain.com&gt;<br>
2019-02-03 18:16:25 SERVER -&gt; CLIENT: 250 2.1.0 OK b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: RCPT TO:&lt;myotheremail@email.com&gt;<br>
2019-02-03 18:16:25 SERVER -&gt; CLIENT: 250 2.1.5 OK b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: DATA<br>
2019-02-03 18:16:25 SERVER -&gt; CLIENT: 354  Go ahead b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Date: Sun, 3 Feb 2019 19:16:24 +0100<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: To: Name &lt;myotheremail@email.com&gt;<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: From: Mailer &lt;no-reply@domain.com&gt;<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Subject: =?iso-8859-1?Q?Tack_f=F6r_att_du_kontaktade_mig?=<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Message-ID: &lt;iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA@192.168.1.182&gt;<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: MIME-Version: 1.0<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Content-Type: multipart/alternative;<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER:    boundary=&quot;b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA&quot;<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Content-Transfer-Encoding: 8bit<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: This is a multi-part message in MIME format.<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: --b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Content-Type: text/plain; charset=us-ascii<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Kvitto<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: --b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: Content-Type: text/html; charset=us-ascii<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: &lt;html style=&quot;font-family: monospace; font-size: 14px; font-weight: normal; margin: 0; padding: 20px 25px; text-align: left;&quot;&gt;&lt;body style=&quot;width: 700px; -webkit-text-size-adjust: none;&quot;&gt;Kvitto&lt;/body&gt;&lt;/html&gt;<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: --b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA--<br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: <br>
2019-02-03 18:16:25 CLIENT -&gt; SERVER: .<br>
2019-02-03 18:16:26 SERVER -&gt; CLIENT: 250 2.0.0 OK 1549217785 b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:26 CLIENT -&gt; SERVER: QUIT<br>
2019-02-03 18:16:26 SERVER -&gt; CLIENT: 221 2.0.0 closing connection b17sm2592394lfc.21 - gsmtp<br>
ok|message_sent

mygmail@email.com的原始标题:

Return-Path: <mygmail@email.com>
Received: from 192.168.1.182 ([1x5.xxx.1x5.xxx])
        by smtp.gmail.com with ESMTPSA id y81-v6sm2393468lje.30.2019.02.03.10.14.54
        for <myotheremail@email.com>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 03 Feb 2019 10:14:54 -0800 (PST)
From: Mailer <mygmail@email.com>
X-Google-Original-From: Mailer <from@example.com>
Date: Sun, 3 Feb 2019 19:14:54 +0100
To: Joe User <myotheremail@email.com>
Subject: Here is the subject
Message-ID: <KzC4ODWsxrNvhHz0qo1FPKQHzBnpDqsBVLYTHeVHDvg@192.168.1.182>
X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="b1_KzC4ODWsxrNvhHz0qo1FPKQHzBnpDqsBVLYTHeVHDvg"
Content-Transfer-Encoding: 8bit

This is a multi-part message in MIME format.
--b1_KzC4ODWsxrNvhHz0qo1FPKQHzBnpDqsBVLYTHeVHDvg
Content-Type: text/plain; charset=us-ascii

This is the body in plain text for non-HTML mail clients

--b1_KzC4ODWsxrNvhHz0qo1FPKQHzBnpDqsBVLYTHeVHDvg
Content-Type: text/html; charset=us-ascii

This is the HTML message body <b>in bold!</b>


--b1_KzC4ODWsxrNvhHz0qo1FPKQHzBnpDqsBVLYTHeVHDvg--

0 个答案:

没有答案