【发布时间】:2022-01-05 14:30:19
【问题描述】:
所以我想从 gmail 地址向 yahoo 地址发送电子邮件。它工作正常,但是当我打开 yahoo 邮件时,它无法识别我从 gmail 地址发送的邮件。例如,我有一个登录确认按钮,当您收到邮件时必须按下该按钮。当我发送到 gmail 地址时,您可以按下按钮,但是当涉及到 yahoo 地址时.. 不 :(。任何想法为什么?以及如何解决这个问题?
$sentTo = $email;
$message = "Confirm registration";
$mail = new PHPMailer;
//$mail->SMTPDebug = 2;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myusername'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('myusername@gmail.com', 'WEBSITE'); //Set who the message is to be sent from
$mail->addAddress($sentTo); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Travel Smart - Confirm Registration - ";
$mail->Body = "<div style='padding: 10px; border-radius: 10px; height: auto; background-image:linear-gradient(to right, rgba(287, 202, 192), rgba(142, 65, 98));opacity:0.8;'><h2 style='font-family:cursive'> WELCOME! </h2> <br> <a href='localhost/log.php?unique_id=$ran_id'><button style='color:white; background:black; pointer: cursor; padding: 10px; border-radius: 20px;'>". $message."</button></a><br></div>";
$mail->AltBody = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
【问题讨论】:
-
您是否尝试过移除 a-tag 内的按钮并改为设置 a-tag 的样式?不同的电子邮件客户端可以以不同的方式解析 HTML 电子邮件,因此最好尽可能降低复杂性。您还应该在链接中的主机名(如
http://localhost)之前包含架构(http://或https://)。如果没有架构,浏览器将假定您正在尝试从您所在的页面访问相对 URL(某些网络邮件客户端可能会阻止) -
另外,本地主机的链接只对你有用,对其他人无效。
-
你不应该用
<a>包裹<button>。使用w3.org 验证结果:元素button不得作为a元素的后代出现。 -
仍然无法正常工作... 雅虎根本无法识别 html
-
@deniz_info 如果您确实删除了位于
a中的button,它会起作用。刚刚测试过。
标签: php email gmail phpmailer yahoo-mail