php mail()出现问题-名称不正确 [英] problem with php mail() - from name doesn't appear correctly

查看:79
本文介绍了php mail()出现问题-名称不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hellHi Folks,

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 <hello@metaldemos.com>
Reply-To: Metaldemos <hello@metaldemos.com>

无论如何,在邮件程序中,名称为 hello。

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

在php中,我使用以下标头:

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 <hello@metaldemos.com>\nReply-To: Metaldemos <hello@metaldemos.com>\nReturn-Path: Metaldemos <hello@metaldemos.com>\n";

以及发送邮件的代码:

mail($email, $subject, $mailbody, $headers,"-t -i -f Metaldemos <hello@metaldemos.com>");

关于如何解决此问题的任何想法吗?

Any idea on how I can fix this?

Greetz&谢谢

Greetz & thanks

梅妮

推荐答案

上面的答案是正确的。您需要在发件人和答复至行的末尾加上 r。就像在所有其他标题行的末尾一样。

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.

根据 SMTP RFC (第2.3.8节行部分)

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


行由零个或多个数据字符组成,这些数据字符以
序列ASCII字符 CR(十六进制值0D)结尾,紧接着是
ASCII字符 LF(十六进制值0A)。此终止序列为
,如本文档中所述。一致的实现必须
不能识别或生成任何其他字符或字符序列
作为行终止符。
服务器可以对行长施加限制(请参见第4节)。

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

此外,出现裸, CR或 LF文本
中的字符(即,没有一个字符)在使用邮件
系统作为工具的邮件实现和应用程序中引起
问题的历史由来已久。 SMTP客户端实现绝不能传输
这些字符,除非当它们用作行终止符
时,然后必须如上所述,仅以
序列传输它们。

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.

所以您的标题行:

$headers="Mime-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: quoted-printable\nFrom: Metaldemos <hello@metaldemos.com>\nReply-To: Metaldemos <hello@metaldemos.com>\nReturn-Path: Metaldemos <hello@metaldemos.com>\n";

无效,HTTP或SMTP标头必须始终以\r\n结尾,而不仅仅是\ \n或\r

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

正确的行将是

$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 <hello@metaldemos.com>\n";
$headers.="Reply-To: Metaldemos <hello@metaldemos.com>\n";
$headers.="Return-Path: Metaldemos <hello@metaldemos.com>\n";

您可以将所有内容排成一长行,我将其分开以使其更清晰。

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

它以前不起作用的原因是,您只更改了FROM和REPLY-TO,因此必须全部更改。

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

这篇关于php mail()出现问题-名称不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆