当我添加 .com.sg 而不仅仅是.com时,PHP 邮件函数无法发送电子邮件


PHP mail function can't send out email when I added .com.sg instead of just .com

我想发送一个链接,供用户在注册后验证他们的帐户。但是当我在$message使用www.singapore.com时,我能够收到电子邮件,但是当我将其改回www.singapore.com.sg时,我无法收到它。我想知道是因为链接还是我的代码中有一些错误?请帮助我。

$domain ='www.singapore.com'; 
$id = mysql_insert_id(); 
$to = 'myemail@gmail.com'; 
$subject = "E-mail Verification"; 
$message = 'Click on the link to verify your account: http://'.$domain.'/rates/activation.php?id='.$id.' '; 
$headers = "From: <Singapore> 'r'n"; 
mail($to,$subject,$message,$headers, '-f enquiry@singapore.com.sg'); 

你需要 -f 信封选项吗? 如果没记错的话,放入其中的任何地址都需要在 sendmail 配置中添加为受信任的用户。

我在PHP邮件文档中找到了这个:

应将运行 Web 服务器的用户添加为受信任用户 到 sendmail 配置,以防止"X-警告"标头 在信封发件人 (-f) 设置为 此方法。对于 sendmail 用户,此文件是/etc/mail/trusted-users。

您只是尝试设置回复地址和发件人地址吗?如果是这样,请使用$header,不要打扰其他参数。

$headers = “From: enquiry@singapore.com.sg” . “'r'n” . “Reply-To: enquiry@singapore.com.sg”;

你的代码有问题。将其更改为此

$message = 'Click on the link to verify your account: http://'.$domain.'/rates/activation.php?id='.$id;

它在最后有额外的引号。

希望有帮助.. :)