首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP Mailer:从gmail向yahoo发送邮件,无法识别的代码

PHP Mailer:从gmail向yahoo发送邮件,无法识别的代码
EN

Stack Overflow用户
提问于 2021-11-28 11:18:51
回答 1查看 47关注 0票数 0

所以我想从gmail地址发送一封电子邮件到yahoo地址。它在工作,但当我打开雅虎邮件时,它无法识别我从gmail地址发送的邮件。例如,我有一个登录确认按钮,当您收到邮件时必须按下该按钮。当我发送到gmail地址时,你可以按下按钮,但当涉及到yahoo地址时。否:(.你知道为什么吗?如何解决这个问题呢?

代码语言:javascript
运行
复制
$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;
            }
EN

回答 1

Stack Overflow用户

发布于 2021-11-28 13:55:27

您的元素不正确。用w3.org验证你的超文本标记语言结果:

元素button不能作为a元素的子元素出现。

您的链接不正确。它是href="localhost/login.php?..."。您应该包括模式(http://https://),因为上面注释了@M.Eriksson。

这是正文消息的修复。

代码语言:javascript
运行
复制
$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/...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70142865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档