n92
n92

Reputation: 7602

Getting empty mails from website

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 <[email protected]> \r\n";
 $headers .= "Request Form: $name ($contactid)";

 $subject = "Request: $name";

 $body = "Name:&nbsp;$name<br />Email:&nbsp;$email<br />Phone:&nbsp;$phone<br/>";

 mail("[email protected]",$subject,$body,$headers);

What is the reason behind it. Is this the problem with the script i have written or the SMTP server.

Upvotes: 0

Views: 127

Answers (1)

Jocelyn
Jocelyn

Reputation: 11393

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 <[email protected]>\r\n";
$headers .= "Request-Form: $name ($contactid)\r\n";

\r : Carriage Return
\n : Line Feed

Does it fix your problem?

Upvotes: 2

Related Questions