PHPMailer: hyperlink displayed in brackets in Outlook

I use phpmailer to send email with a hyperlink on its body. I have this code:

$body = "<a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a>"; require('classes/PHPMailerAutoload.php'); $mail = new PHPMailer; $mail->CharSet = "UTF-8"; $mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = SMTP_HOST; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = SMTP_USER; // SMTP username $mail->Password = SMTP_PASSWORD; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to $mail->setFrom(SMTP_USER); $mail->addAddress($to); // Add a recipient Name is optional $mail->isHTML(true); // Set email format to HTML $mail->Subject = $subject; $mail->Body = $body; $mail->AltBody = $altbody; if(!$mail->send()) { echo $mail->ErrorInfo; } 

When I send an email to a Gmail address and open it in Gmail, the hyperlink looks fine (I can click the link and redirect to the page).

But when I send it to Outlook, the hyperlink looks like this:

[my.domain.com/activate.php?x=52&y=aa1fdf437c526ee219decc1ea72fc266] my.domain.com/activate.php?x=52&y=aa1fdf437c526ee219decc1ea72fc266

Any ideas on what might be wrong?

+5
source share
1 answer

Email clients have different rendering mechanisms.

It looks like gmail will display the link without the http:// or https:// protocol.

Outlook may still require it.

Try using a URL without protocols (without using a scheme): //

$body = "<a href='//".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a>";


EDIT:

Notice @Synchro in the comments:

Anonymous / relative protocol URLs are a bad idea in email, because if you are not in the email client you do not have a basic protocol regarding, and therefore they just break. Make it explicit and it will work everywhere, and these days it's hard to find a good excuse for not using HTTPS.

+4
source

Source: https://habr.com/ru/post/1257557/


All Articles