向用户发送确认电子邮件

问题描述:

我试图在用户注册我的网站时向用户发送包含确认码的电子邮件。该电子邮件发送很好,但是当我把全长URL,邮件没有发送向用户发送确认电子邮件

在这里你可以看到,我使用的代码:我需要把在全

$message = 'You have recieved this email because you have signed up to Amped. To complete the registration process, please 
click on the link below. <br/> <a href=confirm.php?code=' . $row['emailcode'] . '>Click here to complete registration</a>' 

在confirm.php之前的链接工作,但当我这样做,电子邮件不会发送。有任何想法吗?

+0

你在使用什么库?只是'mail()'或更复杂的东西? – Uby 2013-03-27 20:43:47

+0

你是什么意思“电子邮件不发送”。它可能是垃圾邮件过滤器问题吗?你的域名中是否有正确的spf/domain keys条目?您是否尝试过首先手动发送相同的电子邮件。 – 2013-03-27 20:45:47

您正在发送相对路径。你需要使用urlencode发送到文件的完整路径:

$message = '<a href="' . urlencode("http://www.example.com/confirm.php?") . $row['emailcode'] . '">'; 

你缺少报价:

$message = 'You have recieved this email because you have signed up to Amped. To complete the registration process, please click on the link below. <br/> <a href="confirm.php?code=' . $row['emailcode'] . '">Click here to complete registration</a>' 

你应该确保消毒那个url变量,其编码为安全网址的使用,以及然后在confirm.php中对其进行解码。直接将db值转换为url不是一个好主意。 urlencode()是一个不错的解决方案。无法做到这一点couold导致网址中断,并通过扩展,你的脚本。

$code = urlencode($row['emailcode']); 

$msg = "stuff.. <a href='http://www.example.con/confirm.php?code=". htmlentities($code) ."'>Click here</a>";