tags:

views:

363

answers:

4

Hello all,

Is the following "From" header incorect?

 // To send HTML mail, the Content-type header must be set
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 // Additional headers
 $headers .= 'From: Mail Master <[email protected]>' . "\r\n";
if(sendEmailNow($email, $subject, $body, $headers)){

I get the error from my mail server. It says "Mail from error: Syntax error".

Thanks all for any help.

Update

I have stripped down the SendEmailNow function to the below and I get the same error:

//send an email
function sendEmailNow($email, $subject, $body, $headers){

    if (mail($email, $subject, $body, $headers)) {
      ##check email
      ##code to say email sent - compare with the number registered
      return true;
     }

     else {
      ##code to report an error 
      return false;
     }

 }

Update 2

Problem solved. I am running this on a windows machine using PHP 5. Like the correct answer chosen and the comments have said. Some mail servers have trouble understanding what I had previously. But what worked for me was this:

$headers .= 'From: [email protected]' . "\r\n";
+1  A: 

Unless the body is empty, you may need an additional CRLF to terminate the headers. Without knowing the API I can't say much more.

Norman Ramsey
I tried the extra CRLF, I still get the same syntax error. What do you mean by API?
Abs
Probably the sendEmailNow function. What's the code for that?
David Zaslavsky
Ah I see. Its exactly the same as the mail() function - it just checks if the email is in the right format first nothing else.
Abs
+4  A: 

A Google search for the error message suggests that some SMTP servers fail to parse your syntax for the From header. Can you try the following syntax to rule out this possibility?

From: [email protected]
Ayman Hourieh
This is likely to be the culprit, especially if PHP is running under Windows; a shocking number of SMTP servers can't cope with the (perfectly valid) `First Last <email>` syntax.
Rob
I've seen that syntax in the form "First Last" <email>. Try sticking double quotes around the name.
Samir Talwar
A: 

Not sure if this'll help, but here's what the output headers look like in my Python app in pure-text:

Content-Type: multipart/alternative;
    boundary="10.254.26.130.1.1364.1241389770.060.1"
From: User1 <[email protected]>
To: User2 <[email protected]>,User3 <[email protected]>
Subject: Actual subject
MIME-Version: 1.0


--10.254.26.130.1.1364.1241389770.060.1
Content-Type: text/plain;
    charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

actual text content starting here...

Again, without knowing all the content/headers it's hard to say, but I'd guess either a) You've left out the trailing CRLFs before the content, or b) one of the earlier headers missing its CRLF.

Apologies if that takes you in a wildly wrong direction. :)

Caleb
A: 
From: "User1" <[email protected]>

The From header requires quotes for the name part.

Mario