我正在使用PHPMailer发送电子邮件。
$mail = new PHPMailer();
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.live.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "data.edi@outlook.com"; // SMTP username
$mail->Password = "*******"; // SMTP password
$mail->From = "data.edi@outlook.com";
$mail->FromName = "Office";
$mail->addAddress($getEmailAddress);
$mail->IsHTML(true);
$mail->Subject = "SIIX Email Renewal verification";
$mail->Body = "
<div style='line-height: 20px;'>
Dear All Outlook email user,<br><br>
To complete the outlook email renewal this year we need to verify whether this email received successfully or not.<br>
Please kindly help to verify by open the link below to confirm it.<br><br>
<a href='//1.1.1.1:8082/renewal/mail/verify.php?email=$getEmailAddress' style='font-size: 20px; color: #0055a7; font-weight: bold;'>
<img src='http://1.1.1.1:8082/renewal/mail/outlook.png'/><br>
<u>Verify Now</u></a><br><br>
Thank you<br>
Outlook Exchange Mail Administrator<br>
<img src='http://1.1.1.1:8082/renewal/mail/office.jpg'/>
</div>
";
$mail->Send();
当我尝试运行代码时,在电子邮件接收中,我无法在手机上点击Verify Now
。
<a href='//1.1.1.1:8082/renewal/mail/verify.php?email=$getEmailAddress' style='font-size: 20px; color: #0055a7; font-weight: bold;'>
<img src='http://1.1.1.1:8082/renewal/mail/outlook.png'/><br>
<u>Verify Now</u></a>
然后我尝试将其修改为(添加http :)
<a href='http://1.1.1.1:8082/renewal/mail/verify.php?email=$getEmailAddress' style='font-size: 20px; color: #0055a7; font-weight: bold;'>
<img src='http://1.1.1.1:8082/renewal/mail/outlook.png'/><br>
<u>Verify Now</u></a>
尝试运行代码时,我没有看到任何收到的电子邮件。
然后我尝试再次修改它(添加\
):
<a href=\'http://1.1.1.1:8082/renewal/mail/verify.php?email=$getEmailAddress\' style='font-size: 20px; color: #0055a7; font-weight: bold;'>
<img src='http://1.1.1.1:8082/renewal/mail/outlook.png'/><br>
<u>Verify Now</u></a>
然后我尝试再次运行代码并得到链接的结果是:
http://\http://1.1.1.1:8082/renewal/mail/verify.php?email=david.alwis@siix.com.sg\
如何解决这个问题?
日志:
SMTP -> FROM SERVER:220 SG2PR04CA0156.outlook.office365.com Microsoft ESMTP
MAIL Service ready at Wed, 16 May 2018 09:09:58 +0000
SMTP -> FROM SERVER: 250-SG2PR04CA0156.outlook.office365.com Hello [175.111.116.70] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready
SMTP -> FROM SERVER: 250-SG2PR04CA0156.outlook.office365.com Hello [175.111.116.70] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN XOAUTH2 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:250 2.1.0 Sender OK
SMTP -> FROM SERVER:250 2.1.5 Recipient OK
SMTP -> FROM SERVER:354 Start mail input; end with .
SMTP -> FROM SERVER:250 2.0.0 OK [Hostname=SG2PR06MB2122.apcprd06.prod.outlook.com]
SMTP -> FROM SERVER:220 SG2PR04CA0152.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 16 May 2018 09:09:59 +0000
SMTP -> FROM SERVER: 250-SG2PR04CA0152.outlook.office365.com Hello [175.111.116.70] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready
SMTP -> FROM SERVER: 250-SG2PR04CA0152.outlook.office365.com Hello [175.111.116.70] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN XOAUTH2 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:250 2.1.0 Sender OK
SMTP -> FROM SERVER:250 2.1.5 Recipient OK
SMTP -> FROM SERVER:354 Start mail input; end with .
SMTP -> FROM SERVER:250 2.0.0 OK [Hostname=SG2PR06MB2122.apcprd06.prod.outlook.com]
SMTP -> FROM SERVER:220 SG2PR04CA0167.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 16 May 2018 09:10:00 +0000
SMTP -> FROM SERVER: 250-SG2PR04CA0167.outlook.office365.com Hello [175.111.116.70] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready
SMTP -> FROM SERVER: 250-SG2PR04CA0167.outlook.office365.com Hello [175.111.116.70] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN XOAUTH2 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 SMTPUTF8
SMTP -> FROM SERVER:250 2.1.0 Sender OK
SMTP -> FROM SERVER:250 2.1.5 Recipient OK
SMTP -> FROM SERVER:354 Start mail input; end with .
SMTP -> FROM SERVER:250 2.0.0 OK [Hostname=SG2PR06MB2122.apcprd06.prod.outlook.com]
答案 0 :(得分:1)
协议相对URL(以//
开头)无法在电子邮件中工作,因为它们没有相关的协议 - 一般来说,电子邮件消息没有URL。请参阅my answer on this subject。
不要添加斜杠;这不会有帮助。我建议切换到heredoc来设置邮件正文 - 它可以避免完全引用问题,并且变量插值仍然有效。例如:
$mail->Body = <<<EOT
<div style="line-height: 20px;">
Dear All Outlook email user,<br><br>
To complete the outlook email renewal this year we need to verify whether this email received successfully or not.<br>
Please kindly help to verify by open the link below to confirm it.<br><br>
<a href="http://1.1.1.1:8082/renewal/mail/verify.php?email=$getEmailAddress" style="font-size: 20px; color: #0055a7; font-weight: bold;">
<img src="http://1.1.1.1:8082/renewal/mail/outlook.png"/><br>
<u>Verify Now</u></a><br><br>
Thank you<br>
Outlook Exchange Mail Administrator<br>
<img src="http://1.1.1.1:8082/renewal/mail/office.jpg"/>
</div>
EOT;
另一个观察 - 消息正文应该是一个完整的HTML文档,包括html,header和&amp;身体标签 - 你只有一个片段。
当你说&#34;我没有看到任何收到的电子邮件&#34;你的意思是发送电子邮件失败了?您的代码中没有错误检查,因此如果发生错误,您将不会看到错误。将您的代码基于PHPMailer提供的示例,其中做包括基本错误检查。