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);
}
Related
I have a website contact form that sends as an email to my iPhone. The problem is I am getting the following message:
"This message cannot be displayed because of the way it is formatted. Ask the sender to send it again using a different format or email program. multipart/mixed"
Is this has something to do with email content-type and how to fix it in my PHP code.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$sender_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message_body));
$sentMail = mail($recipient_email, $subject, $body, $headers);
You specify the Content-Type as a header string.
Assuming you are appending your headers with the standard dot notation, you would use:
$headers .= "Content-Type: multipart/mixed";
And later this would become the fourth parameter of your mail() function:
mail($address, $subject, $message, $headers);
Here's a basic example:
$address = 'sample#sample.com';
$subject = 'Subject';
$message = 'Message';
$headers = "From: My Name<something#something.com>\n";
$headers .= "Reply-To: something#something.com \n";
$headers .= "Content-Type: multipart/mixed";
mail($address, $subject, $message, $headers);
i get clients who complain about weird characters
 Donation Receipt:
Â
If donor provided extra information, here is the information:
Â
this only happens on AOL. Or at least, seems to only happen there.
this is the mail call.
$headers .= "From: " . "Jewcer <info#myapp.com>" . "\r\n";
$headers .= "Reply-To: " . "info#myapp.com" . "\r\n";
$headers .= "From: " . "<{$fromEmail}>" . "\r\n";
$headers .= "Reply-To: " . "{$fromEmail}" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $title, $content, $headers);
Any idea what might causing this problem? generally it works, just AOL and some other odd clients cause problems
the only thing that worked for me was this:
function utf8mail($to,$s,$body,$from_name="x",$from_a = "info#x.com", $reply="info#x.com")
{
$s= "=?utf-8?b?".base64_encode($s)."?=";
$headers = "MIME-Version: 1.0\r\n";
$headers.= "From: =?utf-8?b?".base64_encode($from_name)."?= <".$from_a.">\r\n";
$headers.= "Content-Type: text/plain;charset=utf-8\r\n";
$headers.= "Reply-To: $reply\r\n";
$headers.= "X-Mailer: PHP/" . phpversion();
mail($to, $s, $body, $headers);
}
from
https://stackoverflow.com/a/7267426/533426
I'm trying to use the below code to send mail, but got the below error
Doesn't mail() take in arrays for headers?
Warning: mail() expects parameter 4 to be string, array given in ../email.php on line 16
code :
<?php
$name = #trim(stripslashes($_POST['name']));
$from = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$to = 'example#gmail.com';
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
PHP mail() need string $to, string $subject, string $message, string $headers
if you want to use an array for the headers
mail($to, $subject, $message, implode("\r\n", $headers));
else change your code in
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
why \r\n (from mail() documentation)?
Multiple extra headers should be separated with a CRLF (\r\n) [...]
If messages are not received, try using a LF (\n) only. Some Unix mail
transfer agents (most notably » qmail) replace LF by CRLF
automatically (which leads to doubling CR if CRLF is used). This
should be a last resort, as it does not comply with » RFC 2822.
side note use "\r\n" and not '\r\n'
As the message says the 4th parameter ($additional_headers) should be a string. So you need to join the array elements:
$headers = implode("\r\n", $headers);
mail($to, $subject, $message, $headers);
From the documentation:
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). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
You make $headers to be a array, but it has to be a string! So just change these lines:
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
to this and concatenate the strings together:
$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$from}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
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.
Is there any way to set the priority of PHP mail()? I looked at the online manual but I can't find any reference to it.
By priority, I mean High, Normal, Low or 1, 2, 3 in the headers. So the recipient knows the urgency of the mail.
Thank you!
That's usually done by setting following fields in the header:
"X-Priority" (values: 1 to 5- from the highest[1] to lowest[5]),
"X-MSMail-Priority" (values: High, Normal, or Low),
"Importance" (values: High, Normal, or Low).
See the following example (taken from php's mail function documentation):
<?php
$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message,$headers);
?>
<?php
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message, $headers);
?>
From: http://www.php.net/manual/en/function.mail.php#91058
Call it with the X-Priority header in the 4th parameter:
mail ( $to, $subject, $message , "X-Priority: 1")
A comment on the PHP mail function documentation said:
<?php
$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message,$headers);
To define a mail priority you have to put this lines in the headers:
<?php
$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message,$headers);
?>
http://php.net/manual/en/function.mail.php
everything didn't work except this for my problem
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: xyz#example.com' . "\r\n";
$headers .= 'Cc: Admin#example.com' . "\r\n";
PS: email body must before the headers.