tags:

views:

38

answers:

2

hellHi Folks,

I have a contact form on my webpage, and it workd fine so far.

Only problem is, that in my mailprogram, the name in the from field doesn't show correctly, although the sourcecode of the email seems correct:

From: Metaldemos <[email protected]>
Reply-To: Metaldemos <[email protected]>

Anyway, in the mailprogram, the name is 'hello'.

In php I use this headers:

$headers="Mime-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: quoted-printable\nFrom: Metaldemos <[email protected]>\nReply-To: Metaldemos <[email protected]>\nReturn-Path: Metaldemos <[email protected]>\n";

and the code for sending the mail:

mail($email, $subject, $mailbody, $headers,"-t -i -f Metaldemos <[email protected]>");

Any idea on how I can fix this?

Greetz & thanks

Maenny

A: 

Try adding both a carriage return and new line character. I know when I'm writing PHP scripts to send mail, I do something similar to the following:

...
$headers.= "From: MCB Web Design <[email protected]>\r\n";
$headers.= "Reply-To: Martin Bean <[email protected]>\r\n";
...
if (mail($to, $subject, $message, $headers)) {
    // email sent
}
else {
    // email failed
}
Martin Bean
Hi, thanks for the reply. I'm afraid that didn't do the trick, it even separated the From and Replay-To from the header and left it in the message body...
Maenny
A: 

The above answer is correct. You need the \r\n at at the end of the "From" and "Reply-To" lines. AS WELL as at the end of ALL the other header lines.

According to the SMTP RFC (section "2.3.8. Lines")

Lines consist of zero or more data characters terminated by the sequence ASCII character "CR" (hex value 0D) followed immediately by ASCII character "LF" (hex value 0A). This termination sequence is denoted as in this document. Conforming implementations MUST NOT recognize or generate any other character or character sequence as a line terminator. Limits MAY be imposed on line lengths by servers (see Section 4).

In addition, the appearance of "bare" "CR" or "LF" characters in text (i.e., either without the other) has a long history of causing problems in mail implementations and applications that use the mail system as a tool. SMTP client implementations MUST NOT transmit these characters except when they are intended as line terminators and then MUST, as indicated above, transmit them only as a sequence.

So your header line of:

$headers="Mime-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: quoted-printable\nFrom: Metaldemos <[email protected]>\nReply-To: Metaldemos <[email protected]>\nReturn-Path: Metaldemos <[email protected]>\n";

is invalid, HTTP or SMTP headers MUST always end with \r\n not just a \n or \r

The correct line would be

$headers="Mime-Version: 1.0\r\n";
$headers.="Content-Type: text/plain; charset=UTF-8\n";
$headers.="Content-Transfer-Encoding: quoted-printable\n";
$headers.="From: Metaldemos <[email protected]>\n";
$headers.="Reply-To: Metaldemos <[email protected]>\n";
$headers.="Return-Path: Metaldemos <[email protected]>\n";

You CAN put it all in one long line that's fine, I just split it up to make it clearer.

The reason it didn't work before is because you only changed FROM and REPLY-TO you have to change all of them.

Viper_Sb