You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHPMailer发送含链接HTML邮件的移动端点击及发送异常问题

Let’s break down your problem and get it sorted step by step. You’re dealing with two frustrating issues:

  • Links starting with // (protocol-relative URLs) aren’t clickable on mobile email clients
  • Adding the http: prefix breaks email delivery, and using escape characters creates malformed URLs like http://\http://...

What’s Causing This?

First, protocol-relative URLs (//example.com) work great on web pages, but many mobile email apps (like iOS Mail or Android Gmail) don’t support them properly—they treat the link as invalid, hence the unclickable "Verify Now" button.

As for the delivery failure when adding http:? The main culprit is your HTML body using escaped entities like < instead of raw HTML tags. Since you’ve set IsHTML(true) in PHPMailer, you don’t need to escape HTML tags—doing so turns your markup into plain text, which can trigger spam filters or cause the email to be rejected. The escape characters you added just made things worse by creating duplicate URL prefixes.

The Corrected Code

Here’s the fixed version of your core code, with key improvements:

$mail = new PHPMailer(); 
$mail->SMTPAuth = true; 
$mail->Port = 587; 
$mail->SMTPSecure = 'tls'; 
$mail->IsSMTP(); 
$mail->Host = "smtp.live.com"; 
$mail->Username = "data.edi@outlook.com"; 
$mail->Password = "*******"; 
$mail->From = "data.edi@outlook.com"; 
$mail->FromName = "Office"; 
$mail->addAddress($getEmailAddress); 
$mail->IsHTML(true); 
$mail->Subject = "SIIX Email Renewal verification"; 

// Use raw HTML (no escaped entities) and full http:// URLs
$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 that this email was received successfully.<br>
    Please click the link below to confirm:<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' alt='Outlook Logo'/><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' alt='Office Logo'/>
</div>
"; 

// Add error handling for easier debugging
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Verification email sent successfully!";
}

Key Fixes Explained

  1. Full http:// URLs: Replaced protocol-relative links with complete URLs to ensure mobile clients recognize them as clickable links.
  2. Raw HTML Markup: Removed escaped entities like &lt;—PHPMailer’s IsHTML(true) setting means it will render raw HTML tags correctly, no escaping needed.
  3. Clean Variable Handling: Used double quotes for the body string so PHP correctly parses the $getEmailAddress variable without extra escape characters.
  4. Error Handling: Added a simple check to catch and display PHPMailer errors, which will help you debug any remaining issues quickly.

Debugging Tips

If you still have delivery issues, enable PHPMailer’s debug mode to get full SMTP logs—this will show you exactly where the process fails:

$mail->SMTPDebug = 2; // 2 = full client + server SMTP conversation

Looking at your existing SMTP log snippet, the initial handshake with Outlook’s server is successful (you’re getting 220 and 250 responses), so the problem is almost certainly in your email content, not the SMTP connection itself.

内容的提问来源于stack exchange,提问作者HiDayurie Dave

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:00:53