php邮件“发件人"标头的问题

problem with php mail #39;From#39; header(php邮件“发件人标头的问题)
本文介绍了php邮件“发件人"标头的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,在用户注册时向他发送电子邮件.

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! 
This is a simple email message.";

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

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

echo "Mail Sent.";
?> 

问题是当邮件投递时,from 标头仍然是munged@box123.bluehost.com,而reply-to 被更改为指定的值.

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 是托管网站的服务器的主机名.

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?

推荐答案

我刚刚注意到您正在尝试使用 gmail 地址作为 from 值.这是行不通的,而且 ISP 覆盖它是正确的.如果您想将回复重定向到您的外发邮件,请使用 reply-to.

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.

适用于许多 ISP 的有效地址的解决方法:

A workaround for valid addresses that works with many ISPs:

尝试在 mail() 命令中添加第五个参数:

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

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

这篇关于php邮件“发件人"标头的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)