Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer: hyperlink appears in brackets in outlook

I use phpmailer to send an 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 the email to a Gmail address and open it in Gmail the hyperlink looks fine (I can click on 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?

like image 895
Vegeta Avatar asked Oct 01 '16 01:10

Vegeta


1 Answers

E-mail clients have different rendering engines.

It appears that gmail will render a link without the http:// or https:// protocol.

Outlook may still require it.

Try using a protocol-less (aka scheme-less) URL: //

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


EDIT:

Note from @Synchro in the comments:

Anonymous/relative protocol URLs are a bad idea in email because unless you're in a webmail client, you have no base protocol to be relative to, and so they just break. Make it explicit and it will work everywhere, and these days it's hard to find a good excuse not to use https.

like image 50
Michael Benjamin Avatar answered Oct 23 '22 05:10

Michael Benjamin