我正在使用下面的功能将我的电子邮件发送到$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 -> CLIENT: 220 smtp.gmail.com ESMTP b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:24 CLIENT -> SERVER: EHLO 192.168.1.182<br>
2019-02-03 18:16:24 SERVER -> 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 -> SERVER: AUTH LOGIN<br>
2019-02-03 18:16:24 SERVER -> CLIENT: 334 VXNlcm5hbWU6<br>
2019-02-03 18:16:24 CLIENT -> SERVER: <credentials hidden><br>
2019-02-03 18:16:24 SERVER -> CLIENT: 334 UGFzc3dvcmQ6<br>
2019-02-03 18:16:24 CLIENT -> SERVER: <credentials hidden><br>
2019-02-03 18:16:25 SERVER -> CLIENT: 235 2.7.0 Accepted<br>
2019-02-03 18:16:25 CLIENT -> SERVER: MAIL FROM:<no-reply@domain.com><br>
2019-02-03 18:16:25 SERVER -> CLIENT: 250 2.1.0 OK b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:25 CLIENT -> SERVER: RCPT TO:<myotheremail@email.com><br>
2019-02-03 18:16:25 SERVER -> CLIENT: 250 2.1.5 OK b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:25 CLIENT -> SERVER: DATA<br>
2019-02-03 18:16:25 SERVER -> CLIENT: 354 Go ahead b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:25 CLIENT -> SERVER: Date: Sun, 3 Feb 2019 19:16:24 +0100<br>
2019-02-03 18:16:25 CLIENT -> SERVER: To: Name <myotheremail@email.com><br>
2019-02-03 18:16:25 CLIENT -> SERVER: From: Mailer <no-reply@domain.com><br>
2019-02-03 18:16:25 CLIENT -> SERVER: Subject: =?iso-8859-1?Q?Tack_f=F6r_att_du_kontaktade_mig?=<br>
2019-02-03 18:16:25 CLIENT -> SERVER: Message-ID: <iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA@192.168.1.182><br>
2019-02-03 18:16:25 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)<br>
2019-02-03 18:16:25 CLIENT -> SERVER: MIME-Version: 1.0<br>
2019-02-03 18:16:25 CLIENT -> SERVER: Content-Type: multipart/alternative;<br>
2019-02-03 18:16:25 CLIENT -> SERVER: boundary="b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA"<br>
2019-02-03 18:16:25 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit<br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: This is a multi-part message in MIME format.<br>
2019-02-03 18:16:25 CLIENT -> SERVER: --b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA<br>
2019-02-03 18:16:25 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii<br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: Kvitto<br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: --b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA<br>
2019-02-03 18:16:25 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii<br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: <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;">Kvitto</body></html><br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: --b1_iY6LYwTvxxmPSL2TmbsrEyCAj3YOzg91tTxWEfLAA--<br>
2019-02-03 18:16:25 CLIENT -> SERVER: <br>
2019-02-03 18:16:25 CLIENT -> SERVER: .<br>
2019-02-03 18:16:26 SERVER -> CLIENT: 250 2.0.0 OK 1549217785 b17sm2592394lfc.21 - gsmtp<br>
2019-02-03 18:16:26 CLIENT -> SERVER: QUIT<br>
2019-02-03 18:16:26 SERVER -> 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--