简体   繁体   中英

Header not display correctly on Email PHP mail

I have the following code to send my emails:

$EmailFrom= "staff@homes.com";
$EmailTo = "alejo@yahoo.com, hunterno1@gmail.com";
$Subject = "Contact The Loft";

$success = mail($EmailTo, $Subject, $Body, $EmailFrom);

When I submit my form it sends the mail correctly but on my email the header is not displayed correctly. Look the following image:

头邮件

I do not want THEHNOGK@SERVER179.WEB-HOSTING.COM be displayed as the header, so that is why i search thru google and i found out that i need to customize my header. So i did the follow, but now the email is not sent. it seems there is something wrong with the headers:

<?php
$EmailFrom= "From: HudsonLofts <staff@hobokenhomes.com>\r\n";
$EmailFrom.= "X-Mailer: PHP/" . phpversion()."\r\n";
$EmailFrom.= "MIME-Version: 1.0" . "\r\n";
$EmailFrom.= "Content-type: text/html; charset=iso-8859-1 \r\n";
$EmailTo = "alejo.ferguson@yahoo.com, hunternova01@gmail.com";
$Subject = "Contact The Hudson Loft";

And this is where i call the mail function:

$success = mail($EmailTo, $Subject, $Body, $EmailFrom);

When i submit the form and check my email account not email is received.

I will appreciate your help. Thanks in advance

I have realized that when i use FROM: the mail is not sent. Moreover the mail function does not work it returns false. BUT it i remove FROM and just use: HudsonLofts then it works but the headers it is not displayed properly on my email :(

See http://php.net/manual/function.mail.php
Try to use \\n instead of \\r\\n in $EmailFrom .

BTW: I would rename $EmailFrom to $additionalHeaders ;-)

EDIT after comment :
If this doesn't work, try just with this one line for the headers:
$EmailFrom = "MIME-Version: 1.0";

Second guess: Omit the \\r\\n at the last header line.

$EmailFrom= "staff@homes.com";
$EmailTo = "alejo@yahoo.com, hunterno1@gmail.com";
$Subject = "Contact The Loft";

$success = mail($EmailTo, $Subject, $Body, $EmailFrom);

$EmailFrom should be:

$EmailFrom= "From: staff@homes.com";

or possibly - but I haven't checked this out -

$EmailFrom= "From: Staff <staff@homes.com>";

since the fourth parameter allows you to send any additional header, not just the From:, and hence you need to specify the full header.

If it still does not work, be aware that some providers rewrite the From: header to prevent abuse (such as setting "From: barack.obama@whitehouse.gov"). If this is the case, you won't be able to override that. But you might be able to clear the sender with your provider if you talk to them.

When using the wrong form of the parameter, everything "worked" because you weren't really setting any From field . When you started doing so, the server might have just dropped the email in the bit bucket without telling you anything; the mail() function would have succeeded, since the mail was delivered to the local queue. mail() could not know, much less tell you, that the local queue would then see the mail expunged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM