Abs
Abs

Reputation: 57926

Is my email header correct?

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

Upvotes: 0

Views: 1168

Answers (5)

crystallove18
crystallove18

Reputation: 101

If you set the "$userEmail" variable in your form, you can have it from them and a reply to. The $email_id is your email it is sent to.

        $to=$email_id;
        $headers = "From: " . strip_tags($userEmail) . "\r\n";
        $headers .= "Reply-To: ". strip_tags($userEmail) . "\r\n";

Upvotes: 0

Mario
Mario

Reputation: 1525

From: "User1" <[email protected]>

The From header requires quotes for the name part.

Upvotes: 0

Caleb
Caleb

Reputation: 11

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

Upvotes: 0

Ayman Hourieh
Ayman Hourieh

Reputation: 137196

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]

Upvotes: 4

Norman Ramsey
Norman Ramsey

Reputation: 202535

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.

Upvotes: 1

Related Questions