所以我想从gmail地址发送一封电子邮件到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;
}发布于 2021-11-28 13:55:27
您的元素不正确。用w3.org验证你的超文本标记语言结果:
元素
button不能作为a元素的子元素出现。
您的链接不正确。它是href="localhost/login.php?..."。您应该包括模式(http://或https://),因为上面注释了@M.Eriksson。
这是正文消息的修复。
$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='https://localhost/log.php?unique_id=$ran_id' style='color:white; background:black; pointer: cursor; padding: 10px; border-radius: 20px;'>Hello world</a><br></div>";别忘了把Hello world替换成你的$message。上面的代码是用于测试的。
截图:

黑色按钮的链接可以单击到https://localhost/...。
https://stackoverflow.com/questions/70142865
复制相似问题