I have php 4.x installed in server, I have a script to send mails, generally 1 Out of 10 mails i receive will have no body but the subject will be there. The mail sending code is below.
$headers = "MIME-Version: 1.0 \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$headers .= "From: Contact Form <contact_form#mycompany.com> \r\n";
$headers .= "Request Form: $name ($contactid)";
$subject = "Request: $name";
$body = "Name: $name<br />Email: $email<br />Phone: $phone<br/>";
mail("myname#gmail.com",$subject,$body,$headers);
What is the reason behind it. Is this the problem with the script i have written or the SMTP server.
According to RFC 2822:
Header fields are lines composed of a field name, followed by a colon (":"), followed by a field body, and terminated by CRLF.
A field name MUST be composed of printable US-ASCII characters (i.e., characters that have values between 33 and 126, inclusive), except colon.
Your header does not follow this format. Some receiving mail servers may be more strict and may refuse your mails because of that. Change it to:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Contact Form <contact_form#mycompany.com>\r\n";
$headers .= "Request-Form: $name ($contactid)\r\n";
\r : Carriage Return
\n : Line Feed
Does it fix your problem?
Related
I'm trying to get a read receipt from my PHP emails, here's my code:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "From: ABC <do-not-reply#abc.com> \n";
$headers .= "Disposition-Notification-To: abc#hotmail.com \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
I tried opening the email on my phone and outlook. In both cases, received no email to confirm that the email was open.
I also tried
$headers .= "Read-Receipt-To: abc#hotmail.com \n";
And
$headers .= "X-Confirm-Reading-To: abc#hotmail.com \n";
Read receipts are entirely up to the receiver, there is no way to guarantee one, and many webmail clients will explicitly ignore this for privacy reasons.
Try using Outlook (the office suite application, not the webmail/hotmail clone, not sure which you used) and seeing if you get a popup that says "do you want to send a read receipt? yes / no"
When i am sending UTF-8 email using mail() from my site . Gmail showing it very nice but outlook showing it like this یب سائٹ Ù
my code is
$to = "xxx#gmail.com";
$subject ="Subject";
$headers = "From: xxxx \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset:UTF-8 \r\n";
$message = "email message";
mail ($to,$subject,$message,$headers);
You might want to add encoding to your subject
$subject='==?UTF-8?Q?Subject?='
and/or a Content-Transfer-Header
$headers.='Content-Transfer-Encoding: quoted-printable'
depending on the message part the encoding problem shows.
For some reason, when php mail() is sent to a text number (via email) i.e. 123456789#vtext.com; the from shows up as the centos apache server output email (apache#host-name.com). However, I've included the correct headers; so when the same mail() is pushed to (for example) gmail it comes and shows normal with all the correct headers / mime type / from.
Any idea?
Here's the code for the normal mail
$headers = "From: Alert#thedomain.com \r\n";
$headers .= "Date: ". date('r') . "\r\n";
$headers .= "Content-Type: text/html; charset=utf-8";
$headers .= "MIME-Version: 1.0 ";
$body = "body message";
mail($userinfo->username,"thedomain",$body,$headers);
And the code for the mobile: (We don't use date/content type/ mime for text msgs, or else the headers shows up in the txt msg)
$headers = "From: Alert#thedomain.com \r\n";
$body = "body message";
mail($userinfo->mobile,"thedomain",$body,$headers);
Try sending with the additional -f flag to the mail function:
mail($userinfo->username,"thedomain",$body,$headers, "-ffromaddress#example.com");
See the manual for more information on additional parameters
I have a couple of simple forms that send an html-only email. Most clients (Gmail, Lotus Notes 8, hotmail/live, windows live mail, outlook express) receive the emails just fine, but Outlook 2007 does not.
The code looks like this:
$data="
<html>
<body>
<strong><u>$sub</u></strong><br><br>
<strong>Name:</strong> {$_POST["nombre"]}<br><br>
<strong>Phone:</strong>{$_POST["telefono"]}<br><br>
<strong>Email:</strong> {$_POST["email"]}<br><br>
<strong>Subject:</strong> {$_POST["asunto"]}<br><br>
<strong>Question:</strong> {$_POST["consulta"]}</strong>
</body>
</html>";
$header = "Reply-To: $from\r\n";
$header .= "From: \"".$_POST["nombre"]."\" <$from>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$enviado = mail($destino,$sub,$data,$header);
($from is the only part of the message validated)
The message received by the customer looks like this:
Content-Type: text/html; charset=iso-8859-1
From: Consulta de "Boss" <boss#myfirm.com>
Reply-To: boss#myfirm.com
X-Mailer: PHP/
<strong><u>Solicitud de envío de recetas -
CLIENT</u></strong><br><br><strong>Nombre y Apellido:</strong>
Boss<br><br><strong>Email:</strong>
boss#myfirm.com<br><br><br>
Any ideas?
Have you tried sending multipart email, when doing this we never had issues with outlook 2k3 and 2k7 (excepts poor HTML rendering)
<?php
$header = "From: Sender <sen...#domain.org>\r\n";
$header .= "Reply-to: Sender <blabla...#domain.net>\r\n";
$header .= "X-Mailer: Our Php\r\n";
$boundary = "==String_Boundary_x" .md5(time()). "x\r\n";
$boundary2 = "==String_Boundary2_y" .md5(time()). "y\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/related;\r\n";
$header .= " type="multipart/alternative";\r\n";
$header .= " boundary="$boundary";\r\n";
$message = "If you read this, your email client doesn't support MIME\r\n";
$message .= "--$boundary\r\n";
$message .= "Content-Type: multipart/alternative;\r\n";
$message .= " boundary="$boundary2";\r\n";
$message .= "--$boundary2\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "Alternative message in plain text format.\r\n";
$message .= "--$boundary2\r\n";
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "<html><body><p>HTML formatted message</p></body></html>";
You can replace boundaries with whatever you want, but they must be unique.
For more powerful and flexible email sending in php I suggest to use SwiftMailer
EDIT : as Outlook 2007 has a really dumb HTML renderer, you can also try fixing your markup, there is a </font> never opened in your example, dunno if it's the real mail or a typo in question.
I had a very similar problem, try removing the /r from your returns and use only /n. Outlook andd hotmail have trouble with /r/n.
I confirm the experience with Exchange janmoesen has shared.
Had to change CRLF in headers to just LF, then it started working.
(Thank you Microsoft, once again, for having me work 40% time extra.
Also a real thank you to janmoesen for pointing this! This search is over.)
I encountered the same problem with Outlook 2007.
The answer is simple : replace \r\n by \n
I have had trouble with Exchange (not just Outlook) and CRLF in headers with similar results. Basically, we were sending mails (using PHP on Debian with Postfix) with CRLF-separated headers, which would get mangled in Exchange upon arrival. When I changed those \r\n to simply \n, the problem was gone. ("RFCs be damned!", eh?)
YMMV, obviously, since it is not clear whether your other mail clients connect to the same server as Outlook, or use separate servers altogether.
If the message is in HTML you need to identify it as such:
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
I have always had better luck with MIME encoded HTML mails. Even if there is just one part, I typically use multipart/mixed and explicitly set the content type (text/html). I'm not very familiar with PHP, but the PEAR::Mail_Mime package looks like a candidate.
http://pear.php.net/package/Mail_Mime
Outlook shouldn't have a problem handling it. (emphisis on shouldn't).
There are lots of problems with HTML email in Outlook 2007.
http://www.molly.com/2007/01/18/what-happened-with-html-and-css-in-outlook-2007/
http://fixoutlook.org/
http://www.developertutorials.com/tutorials/html/microsoft-complicates-html-emails-with-outlook-2007-070130/page1.html
and so on.
I'm having a challenge with sending emails with arabic content using PHP's mail function. Let's say I have this simple arabic string:
بريد
I've tried several ways to utilize the headers, but the emails content all still end up with something like: X*X1X(X1Y X/. However, the email subject is correctly encoded if I use arabic characters (thanks to the base64_encode, see function below)
Here's one of the email functions I've tried
function sendSimpleMail($to,$from,$subject,$message) {
$headers = 'MIME-Version: 1.0' ."\r\n";
$headers .= 'To: '.$to ."\r\n";
$headers .= 'From: '.$from . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8; format=flowed' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'."\r\n";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=',$message, $headers);
}
Any suggestions on alternative ways to achieve this goal?
Unfortunately, 8bit encoding is not reliable in e-mail. Many mail transport agents will remove the top bit of every byte in the mail body. بريد is "\xD8\xA8\xD8\xB1\xD9\x8A\xD8\xAF" in UTF-8 bytes; remove the top bit from those bytes and you get ASCII "X(X1Y\nX/".
The way to get non-ASCII characters into a mail body is to set Content-Transfer-Encoding to either base64 or quoted-printable, and the encode the body with base64_encode or quoted_printable_encode, respectively.
(quoted-printable is better if the mail is largely ASCII as it retains readability in the encoded form and is more efficient for ASCII. If the whole mail is Arabic, base64 would probably be the better choice.)
$boundary = uniqid(rand(), true);
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\n";
$headers .= "This is a MIME encoded message.\n\n";
$headers .= "--$boundary\n" .
"Content-Type: text/plain; charset=UTF-8 \n" .
"Content-Transfer-Encoding: base64\n\n";
$headers .= chunk_split(base64_encode($plaintext));
$headers .= "--$boundary\n" .
"Content-Type: text/html; charset=ISO-8859-1\n" .
"Content-Transfer-Encoding: base64\n\n";
$headers .= chunk_split(base64_encode($msg));
$headers .= "--$boundary--\n" .
mail($address, $subject, '', $headers);
This one works for me.
Try this
$headers .= 'From: =?UTF-8?B?'.base64_encode($from). "\r\n";
Your code works for me as-is.
Are you sure that $message contains a valid UTF-8 string?