0

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:&nbsp;$name<br />Email:&nbsp;$email<br />Phone:&nbsp;$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.

n92
  • 7,424
  • 27
  • 93
  • 129
  • Your code suppose to throw an error "Parse error: syntax error, unexpected T_STRING....." post correct code – Muthu Kumaran Aug 09 '12 at 11:41
  • 1
    Looks like you've got a rogue quote at the end of this line `$headers .= "Reply-To: ".$name."'`; – martynthewolf Aug 09 '12 at 11:48
  • that was a typing mistake, I have corrected it, basically I am trying to say is that I can receive mails without any parse errors but 1 out of ten mails will be empty in body – n92 Aug 09 '12 at 12:01
  • Here syntax is not the isssue, its about getting empty emails very oftenly. – n92 Aug 09 '12 at 12:15
  • Can you add your `mail()` call to your question? – Jocelyn Aug 09 '12 at 13:37
  • @Vinay: If you've not posted your *exact* code in the question, people won't be able to tell whether your code is at fault or not. It's important to be accurate! A single character wrong in your script could be the difference between working and non-working code. Copy and paste, don't re-type. – Dan Puzey Aug 09 '12 at 13:48
  • "Request Form" is not a valid header name, and the space is a violation of RFC5322. – tripleee Aug 09 '12 at 14:11

1 Answers1

2

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?

Jocelyn
  • 11,209
  • 10
  • 43
  • 60