问题与php邮件'从'标题 [英] problem with php mail 'From' header

查看:86
本文介绍了问题与php邮件'从'标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的代码(其主旨):

 <?php 
$ to =helloworld@gmail.com;
$ subject =测试邮件;
$ message =你好!\\\
这是一个简单的电子邮件。;

$ headers =From:munged@gmail.com;
$ headers。=\r\\\
Reply-To:munged@gmail.com;
$ headers。=\r\\\
X-Mailer:PHP /。phpversion();

mail($ to,$ subject,$ message,$ headers);

echoMail Sent。
?>

问题是当邮件发送时,头标保持 @ box123.bluehost.com ,而答复更改为指定的值。



box123.bluehost。 com 是托管网站的服务器的主机名。



那么我做错了什么?我可以怎么做From地址与回复地址相同?



是我做错了,还是网络主机播放

解决方案

编辑:我刚刚注意到您正在尝试使用gmail地址作为from值。 这不会工作,ISP正好覆盖它。如果要将回复重定向到您的外发邮件,请使用回复



有效地址的解决方法可以使用许多ISP:



尝试向您的 mail()命令添加第五个参数:

 邮件($ to,$ subject,$ message,$ headers, -  f your@email.here); 


I'm building a website that sends and email to a user when he registers.

My code (the gist of it):

<?php
$to = "helloworld@gmail.com";
$subject = "Test mail";
$message = "Hello! \nThis is a simple email message.";

$headers = "From: munged@gmail.com";
$headers .= "\r\nReply-To: munged@gmail.com";
$headers .= "\r\nX-Mailer: PHP/".phpversion();

mail($to,$subject,$message,$headers);

echo "Mail Sent.";
?> 

the problem is that when the mail is delivered, the from header remains munged@box123.bluehost.com, while reply-to gets changed to the specified value.

box123.bluehost.com is the hostname of the server on which the website is hosted.

So what am I doing wrong? What can I do to get the "From" address the same as the reply-to address?

Is it something I'm doing wrong, or is the web host playing foul?

解决方案

Edit: I just noted that you are trying to use a gmail address as the from value. This is not going to work, and the ISP is right in overwriting it. If you want to redirect the replies to your outgoing messages, use reply-to.

A workaround for valid addresses that works with many ISPs:

try adding a fifth parameter to your mail() command:

mail($to,$subject,$message,$headers,"-f your@email.here");

这篇关于问题与php邮件'从'标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆