簡體   English   中英

來自電子郵件的php mail()與我通過標頭發送的郵件不同

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

我正在嘗試使用郵件功能發送電子郵件,盡管該電子郵件在我的本地計算機上通過,但不在托管服務器上。 兩台服務器上非常不合適的一件事是我嘗試使用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);

這是什么原因造成的,我該如何解決? 非常感謝

您還需要設置“ Reply-to”標題。 如果“發件人”與發件人不匹配,大多數電子郵件客戶端將忽略它。

或者,您可以使用任意數量的預先編寫的庫。 例如, 這是我的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM