tags:

views:

151

answers:

5

I have a website in wich 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 got more reponses from users but I suspect that not every message reach its destination.

How can I be sure that the messages reach theirs destination?

Wich 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");

Thanks

A: 

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]");
Eineki
+3  A: 

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

From PHP.net

Multiple extra headers should be separated with a CRLF (\r\n).

Ólafur Waage
A: 

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 [email protected]", because it may cause trouble, due to the way the mail() function is implemented on windows platform, the "to" address may be parsed incorrectly.

rogeriopvl
A: 

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).

x-way
+4  A: 

You should use external library for working with e-mails in php like PhpMailer , SwiftMailer or Zend_Mail. All your problems will go away.

glavić