【问题标题】:php mail() from email not the same as what I sent through header来自电子邮件的 php mail() 与我通过标题发送的不同
【发布时间】:2014-10-14 19:23:18
【问题描述】:

我正在尝试使用邮件功能发送电子邮件,虽然电子邮件在我的本地通过,但它不在托管服务器上。两台服务器上非常不合适的一件事是我尝试使用 mail() 传递标头的“发件人”电子邮件地址。

两台服务器都获得了相同的“发件人”电子邮件地址来发送我的代码。但我的电子邮件结果非常不同。我收件箱中的电子邮件中的“发件人”电子邮件地址有 我的本地服务器的“myname@my-name.local” 我的托管服务器的“www-data”

我在电子邮件“发件人”标头中设置的内容是:noreply@domain.com

$to = "my.name@gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address

date_default_timezone_set('America/Los_Angeles');
$date = date("F j, Y, g:i a");

$title = checkValue('title', $_POST['title']);
$first_name = checkValue('first name', $_POST['first-name']);
$last_name = checkValue('last name', $_POST['last-name']);
$email = checkValue('email address', $_POST['email']);
$state = checkValue('state', $_POST['state-province']);
$zip = checkValue('zip', $_POST['zip']);
$city = checkValue('city', $_POST['city']);
$country = checkValue('country', $_POST['country']);
$addressOne = checkValue('address 1', $_POST['address-1']);
$addressTwo = checkValue('address 2', $_POST['address-2']);

// get phone and format
$phoneArr = checkArrayValues($_POST['phone']);
$phone = '['.$phoneArr['0'].'] ['.$phoneArr['1'].'] ['.$phoneArr['2'].']';

// get fax and format
$faxArr = checkArrayValues($_POST['fax']);
$fax = '['.$faxArr['0'].'] ['.$faxArr['1'].'] ['.$faxArr['2'].']';

$message = checkValue('message', $_POST['message']);
$topic = checkValue('topic', $_POST['subject']);

$emailBody =  '
<html>
    <head>
        <title>HELLO</title>
    </head>
        <body>
            <label>##Referrer##www.zout.com/contact-us##</label><br />
            <label>##Date## '.$date.'##</label><br />
            <label>##Topic## '.$topic.'##</label><br />
            <label>##First Name## ['.$first_name.']##</label><br />
            <label>##Last Name## ['.$last_name.']##</label><br />
            <label>##Street## ['.$addressOne.'], ['.$addressTwo.']##</label><br />
            <label>##Postal Code## ['.$zip.']##</label><br />
            <label>##City## ['.$city.']##</label><br />
            <label>##State## ['.$state.']##</label><br />
            <label>##Country of residence## ['.$country.']##</label><br />
            <label>##Phone## ['.$phone.']##</label><br />
            <label>##Fax## ['.$fax.']##</label><br />
            <label>##Email## ['.$email.']##</label><br />
            <label>##Message## ['.$message.']##</label><br />
        </body>
    </html>'; 
    $headers = -"From: noreply@domain.com" . "\r\n";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    mail($to,$topic,$emailBody,$headers);

这是什么原因,我该如何解决? 非常感谢

【问题讨论】:

  • 请添加您的 PHP 代码

标签: php email


【解决方案1】:

您还需要设置“回复”标题。如果“发件人”与发件人不匹配,大多数电子邮件客户端将忽略它。

或者您可以使用任意数量的预先编写的库。 Here's 我的,例如。

【讨论】:

  • 非常感谢您的指点。我能够修复它。在此过程中注意到我的 $header 构造中有语法错误。
猜你喜欢
  • 2011-11-18
  • 2016-08-29
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 2016-04-06
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
相关资源
最近更新 更多