沃梦达 / 编程问答 / php问题 / 正文

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邮件“发件人"标头的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:php邮件“发件人"标头的问题

基础教程推荐