Reputation: 2984
I have a website in which I send a confirmation mail as part of the registration process.
Some time ago, I had some troubles with the mails I sent since I used no headers (PHP mail function).
Once I put some headers, I've gotten more responses from users, but I suspect that not every message reaches its destination.
How can I be sure that the messages reach their destination?
Which are the headers that can be considered a 'must'?
This is the code of my SendMail function
mail($to,
$subject,
$message,
"MIME-Version: 1.0\n".
"Content-type: text/plain; charset=ISO-8859-1; format=flowder\n".
"Content-Transfer-Encoding: 8bit\n".
"Message-Id: <" . md5(uniqid(microtime())) . "@mysite.com>\n".
"Return-Path: <[email protected]>\n".
"X-Mailer: PHP v".phpversion()."\n".
"From: admin@ mysite.com");
Upvotes: 0
Views: 625
Reputation: 11
This is a working mail function I'm using for html mail and variable $return is defined to get error report from mail server in case of fail delivery.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$from.'>' . "\r\n";
$return = '-f'.$from;
@mail($to, $subject, $msg, $headers, $return);
you can see more detail at here sugunan.com
Upvotes: 1
Reputation: 43572
You should use external library for working with e-mails in php like PhpMailer , SwiftMailer or Zend_Mail. All your problems will go away.
Upvotes: 4
Reputation: 896
You should add a Date:
header (its mandatory by RFC5322) and some mail-clients may assume January 1 1970 as an e-mail date if none is given (and it gets lost between all the other old messages).
Upvotes: 0
Reputation: 54104
The headers look ok, except for the details pointed by @Eineki. Also if you are using Windows you need to send the $to param in the form "[email protected]" and not "Username ", because it may cause trouble, due to the way the mail() function is implemented on windows platform, the "to" address may be parsed incorrectly.
Upvotes: 0
Reputation: 70001
The headers need a white space at the bottom to separate the header from main body. Tools like Spam Assassin will give you a big mark down for that.
Also you should use \r\n
as a line terminator instead of just \n
Multiple extra headers should be separated with a CRLF (\r\n).
Upvotes: 3
Reputation: 14959
The headers seems quite good to me. The only glitch I see is an extra whitespace in the From header.
I'm sure you already checked it, but just in case ...
"From: admin@ mysite.com");
should be (?)
"From: [email protected]");
Upvotes: 1