简体   繁体   中英

Href link not working in PHP mail

I tried to find a solution, but so far, I wasn't able to find anything suitable for my problem.

I want to send a registration mail to every new user I have, this is the PHP for my mail:

<?php
$message = '<html>
<body>
<p>Hi ' . $fname . ',</br></br>
welcome!</p>
<p>
<a href="\http://www.home.com/en/verification.php?id=' . $db_id . '&code=' . $code . '\">Please click this link</a> to activate your account.</p>
<p>We hope you enjoy our page and are happy to hear about your experiences!</p>
<p>Your team</p>';

$header  = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$header .= "From: Sender <sender@sender.com>";
$header .= "X-Mailer: PHP ". phpversion();

mail($email, 'Thank you for registering!', $message, $header);
?>

Somehow the link is not working correctly in my mails. In Outlook, my Href appears in brackets (eg [ http://www.home.com/en/verification.php?id=4&code=5] ) and in Gmail, only my link description is displayed, but I'm not able to click the link.

Anybody who can help me out?

Your markup is incorrect:

  • it is <br/> and not </br> .
  • You do not need to put in html tag
  • No need to put \\ before and after link

 <?php $message = '<p>Hi ' . $fname . ',<br/><br/>welcome!</p><p><a href="http://www.home.com/en/verification.php?id=' . $db_id . '&code=' . $code . '">Please click this link</a> to activate your account.</p><p>We hope you enjoy our page and are happy to hear about your experiences!</p><p>Your team</p>'; $header = "MIME-Version: 1.0\\r\\n"; $header .= "Content-type: text/html; charset=iso-8859-1\\r\\n"; $header .= "From: Sender <sender@sender.com>"; $header .= "X-Mailer: PHP ". phpversion(); mail($email, 'Thank you for registering!', $message, $header); ?> 

不需要转义。

<a href="http://www.home.com/en/verification.php?id=' . $db_id . '&code=' . $code . '">Please click this link</a> to activate your account.</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM