0

So I want to send an email from gmail address to yahoo address. It's working, but when I open the yahoo mail, it doesn't recognize the message I've sent from the gmail address. For example, I have a button for login confirmation that you have to press when you receive the mail. When I send to a gmail address, you can press the button, but when it comes to yahoo address.. nope :(. Any ideas why? And how to fix this?

$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;
            }
deniz_info
  • 23
  • 6

1 Answers1

0

You have incorrect elements. Validate your HTML with w3.org result:

The element button must not appear as a descendant of the a element.

Your link is incorrect. It is href="localhost/login.php?...". You should include the schema (http:// or https://) as @M. Eriksson was commented above.

This is fix for body message.

$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>";

Don't forget to replace Hello world to your $message. The code above is for testing.

Screenshot: Test send email to yahoo.com

The link that is black button is clickable to https://localhost/....

vee
  • 4,506
  • 5
  • 44
  • 81
  • And why the background isn't visible? – deniz_info Nov 28 '21 at 15:01
  • You did not mentioned anything about background from the first time. And I use almost all of your HTML except reformat `a` to be valid by remove `button` inside it. I did not modify your css background. If that is not working it means it should not working from your code too. As M. Eriksson was commented on your question, _Different email clients can parse HTML emails differently_. This is included CSS. – vee Nov 28 '21 at 15:07
  • Check limitation [here](https://www.htmlemailcheck.com/check/) result: _The background-image style is not supported in 15 known email clients and should be avoided from implementing._ The answer about [background linear-gradient on Yahoo](https://stackoverflow.com/a/55466541/128761). – vee Nov 28 '21 at 15:16