简体   繁体   English

Href链接在PHP邮件中不起作用

[英]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:

<?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. 在Outlook中,我的Href出现在方括号中(例如[ http://www.home.com/en/verification.php?id=4&code=5] ),在Gmail中,仅显示我的链接描述,但我没有能够单击链接。

Anybody who can help me out? 有人可以帮助我吗?

Your markup is incorrect: 您的标记不正确:

  • it is <br/> and not </br> . <br/>而不是</br>
  • You do not need to put in html tag 您不需要放入html标记
  • 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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