简体   繁体   English

来自电子邮件的php mail()与我通过标头发送的邮件不同

[英]php mail() from email not the same as what I sent through header

I am trying to send an email using the mail function, while the email goes through on my local, it is not on hosted server. 我正在尝试使用邮件功能发送电子邮件,尽管该电子邮件在我的本地计算机上通过,但不在托管服务器上。 The one thing that is very out of place on both servers is the "from" email address I am trying to pass through the header using mail(). 两台服务器上非常不合适的一件事是我尝试使用mail()通过标头传递的“发件人”电子邮件地址。

Both servers are getting the same "from" email address to send in my code. 两台服务器都使用相同的“发件人”电子邮件地址来发送我的代码。 But my email results are very different. 但是我的电子邮件结果却大不相同。 There the "From" email address in the emails that are in my inbox have "myname@my-name.local" for my local server "www-data" for my hosted server 收件箱中的电子邮件中的“发件人”电子邮件地址中,本地服务器的名称为“ myname@my-name.local”,托管服务器的名称为“ www-data”

What I have it set as in my email "from" header is: noreply@domain.com 我在“发件人”邮件头中设置的内容是: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);

What is the cause for this and how can I fix it? 这是什么原因造成的,我该如何解决? Thanks a lot 非常感谢

You'll need to set the "Reply-to" header as well. 您还需要设置“ Reply-to”标题。 If the "from" doen't match the sender most email clients will ignore it. 如果“发件人”与发件人不匹配,大多数电子邮件客户端将忽略它。

Or you could use any number of pre-written libraries. 或者,您可以使用任意数量的预先编写的库。 Here's mine, for example. 例如, 这是我的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google企业应用套件:未接收到PHP邮件发送的来自同一域的电子邮件 - Google Apps: Not receiving email from same domain sent by PHP mail() PHP的邮件功能-如何更改标题中的发件人:不发送电子邮件? - php mail function - how can changing From: in header cause email not to be sent? 格式化通过PHP和IIS7与mail()一起发送的电子邮件 - Formatting my email sent with mail() through PHP, and IIS7 Postfix / PHP Mail()以相同的电子邮件地址发送电子邮件,忽略标头$ from - Postfix / PHP Mail() sends email as same email address, ignores header $from 如何隐藏php邮件发送的电子邮件中的“收件人”字段 - How can I hide the 'to' field in the email sent by php mail 为什么 html 没有显示在我使用 php mail() function 发送的 email 中? - Why html not showing in the email i sent using php mail() function? 如果从php mail()函数发送的电子邮件返回,它在linux中的位置? - If an email sent from php mail() function returns, where is it located in linux? PHP表单-密件抄送邮件未从电子邮件表单发送 - PHP Form - bcc mail not sent from email form 如何自定义从php mail()脚本发送的电子邮件的方式 - How to customize the way an email looks sent from a php mail() script 邮件标题以使用php答复电子邮件 - Mail header to answer to a email with php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM