PHP mail sends but sender is always "Apache <apache#hosting12" - php

In my mail client or gmail the sender is always apache#hosting12
Any way to fix this issue?
I have tried setting the headers like these with no success. Can sombody please help me?
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'$from'> \r\n";
$headers .= "Reply-To: <'$from'> \r\n";
$headers .= "Return-Path: <'$from'>\r\n";
$headers .= "X-Mailer: PHP \r\n";
or
$headers = "From: $from";

I found that answer on a french forum.
http://www.developpez.net/forums/d413965/php/outils/configuration-sendmail_path-sender/
You can add a 5th param to the mail function:
mail($mail_recipient, $subject, $message, $headers, '-f'.$mail_from);
Ths '-f' + mail_from force the system to send the email as the mail_from.

There are extra single quotes in your header. Try like this:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <$from> \r\n";
$headers .= "Reply-To: <$from> \r\n";
$headers .= "Return-Path: <$from>\r\n";
$headers .= "X-Mailer: PHP \r\n";
Also you can remove the unnecessary "Reply-To" and "Return-Path".

Please remove single quotation mark from around $from and use {$from}
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
or you can use following signatures to pass from
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
EDIT:
You also want to check sendmail_from setting in php.ini file.

Related

Want to put button instead of link in mail

I want to convert the link to the button in PHP mail.php file.
$message = sprintf($this->language->get('mail_message'), $store_name, $link);
I will appreciate if someone helps me to convert the link to the button.
To achieve this, you have to send html email instead of plain/text email. It is pretty simple, leave the images on the server and send the PHP + CSS to them...
$to = 'xyz#example.com';
$subject = 'Subject';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: abc#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p>Anchor Text</p>';
mail($to, $subject, $message, $headers);

Remove auto line break in html email

I would like to know how can I remove the auto line break in email. I am using the phpmailer function:
$from = 'dass#gmail.com';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "Reply-To: admin#gmail.com \r\n";
$returnPath = "-r".$from;
mail($to, $subject, $msgbody, $headers, $returnPath)
Here is a running example:
jsfiddle.net/qwyh0551/
Replace this code:
<td>What ki
nd
By this code:
<td>What kind
And your problem is gone. The french fries link does work in the fiddle, so I assume you already fixed that.

PHP Mail Reply-To: hotmail issue

I have a contact form that generates an email. If the customer has an Hotmail account (that I put in the Reply-To part of the header) then the email is not sent, any other email address is fine and the email sends without a problem.
For example:
if $contactEmail is mail#hotmail.com the email is not sent.
if $contactEmail is mail#site.com the email is sent.
Here is my Header ...
$headers = "From: My Site <info#mysite.com>\r\n";
$headers .= "X-Sender: <info#mysite.com>\r\n";
$headers .= "Reply-To: $contactEmail\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Mailer: PHP4\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "Return-Path: <info#mysite.com>\r\n";
Any thoughts/advice please?
Thanks.
As per the PHP manual regarding sending HTML mail, try adding the "to" header:
$headers = "From: My Site <info#mysite.com>\r\n";
$headers .= "To: Whoever <whoever#othersite.com>\r\n";
$headers .= "X-Sender: <info#mysite.com>\r\n";
$headers .= "Reply-To: $contactEmail\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Mailer: PHP4\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "Return-Path: <info#mysite.com>\r\n";
Try jerdiggity's answer first and check if the mail ends in the junk folder. Microsoft's SmartScreen spam technology is very hard to come by. You have to create an DNS SPF record and “un-junk” some mails in order to get your IP whitelisted.

php mail function - how can changing From: in header cause email not to be sent?

The one email From:support#lead.com works fine. But when changed to john.doe#lead.com it doesn't work? See below.
Both are valid email addresses (fictitious for this example) in the domain from which they are sent.
I have the question into Netfirms support too. I expect to move to phpmailer or API to a ESP (e.g., mailchimp) account soon, but this is just bugging me that the little change breaks the email function.
Code:
Works:
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: support#lead.com' . "\r\n";
$headers .= 'Bcc: bcc#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#mylead.com")) echo ("Message delivery failed");
Doesn't Work: (only changed support to john.doe):
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: john.doe#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#lead.com")) echo ("Message delivery failed");
Don't know how this really should matter, but you're mixing \n and \r\n in the headers, which may confuse your mail server... Would you mind to try this out?

PHP Mail Headers are Being Sent Within The Body

function sendEmail($address,$subject,$message)
{
$headers = "Reply-To: miloAds Team <admin#miloads.com>\r";
$headers .= "Return-Path: miloAds Team <admin#miloads.com>\r";
$headers .= "From: miloAds Team <admin#miloads.com>\r";
$headers .= "Organization: Milonas Media LLC\r";
$headers .= "MIME-Version: 1.0\r";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r";
$headers .= "X-Priority: 3\r";
$headers .= "X-Mailer: PHP". phpversion() ."\r";
mail($address, $subject, $message, $headers);
}
When sending out an email, the header is appearing in the body.
Try changing each of the \r escapes to \r\n and see if that helps.
Quoth the PHP manual:
additional_headers (optional)
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc).
Multiple extra headers should be separated with a CRLF (\r\n).
Make sure to not include the trailing \r\n on the last header either.
Also make sure to strip any newlines from the $subject as that could cause problems. See if those help.
Add \n to \r, i.e. \r\n and remove the last one:
function sendEmail($address,$subject,$message)
{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: miloAds Team <admin#miloads.com>\r\n";
$headers .= "Reply-To: miloAds Team <admin#miloads.com>\r\n";
$headers .= "Organization: Milonas Media LLC\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion();
mail($address, $subject, $message, $headers);
}

Categories