简体   繁体   English

PHP邮件标题问题

[英]PHP Mail Headers Problem

I'm creating a simple PHP mail function. 我正在创建一个简单的PHP邮件功能。 I have a small problem with its header. 我的标题有一个小问题。 I'm trying to set the senders name to be the clients website, and when I use the following code: 我正在尝试将发件人名称设置为客户网站,并且在使用以下代码时:

$headers = "From: Websites' Name";
$headers .= "\nMIME-Version: 1.0\n"."Content-Type:  multipart/mixed;\n"." boundary=\"{$mime_boundary}\"";
$headers .= "Reply-To:  $email <$email>\n";
$headers .= "X-Sender:  $email <$email>\n";
$headers .= "X-Priority: 1\n";

I receive the E-mail and the sender would be "Websites' Name@h184905.safesecureweb.com". 我收到电子邮件,发件人为“网站的名称@ h184905.safesecureweb.com”。 What I want is, to get rid of the "@h184905.safesecureweb.com" I only want the "Websites' Name" to appear ... Can anyone help me with that ??? 我想要的是摆脱“ @ h184905.safesecureweb.com”,我只希望显示“网站的名称” ...有人可以帮我吗?

Thanks 谢谢

This is not possible. 这是不可能的。 An E-Mail needs a valid from address. 电子邮件需要一个有效from地址。

The best you can do is what you already do in the other headers: 您可以做的最好的事情就是您已经在其他标题中执行的操作:

$headers = "From: \"Websites' Name\" <email@example.com>";

(insert your valid E-Mail [must be on the same server] for the example address) (为示例地址插入有效的电子邮件[必须在同一服务器上])

I am assuming the Websites' is an example only - you may need to escape the quote character otherwise. 我假设“ Websites'只是一个示例-否则,您可能需要转义引号字符。

You need to set a valid From header - that is, a valid e-mail address. 您需要设置一个有效的From头-即一个有效的电子邮件地址。 You can do this: 你可以这样做:

From: "Websites' Displayed Name" <some@address.example.com>

Note that if you have a space in the displayed name, you need to enclose it in double quotes, (and for non-ASCII characters (eg "ščřž"), you'll need to use quoted-pritable or base64). 请注意,如果显示名称中有空格,则需要将其用双引号引起来(对于非ASCII字符(例如“ščřž”),则需要使用带引号的pritable或base64)。

As already mentioned, you need to provide a valid mailbox in the From field. 如前所述,您需要在“ From字段中提供有效的邮箱。 You can use imap_rfc822_write_address for that: 您可以imap_rfc822_write_address使用imap_rfc822_write_address

$headers = array(
    "From: ".imap_rfc822_write_address("info", "example.com", "Website's Name"),
    "MIME-Version: 1.0",
    "Content-Type: multipart/mixed; boundary=\"{$mime_boundary}\"",
    "Reply-To: ".imap_rfc822_write_address("info", "example.com", "Website's Name"),
    "X-Sender: ".imap_rfc822_write_address("info", "example.com", "Website's Name"),
    "X-Priority: 1"
);
$headers = implode("\r\n", $headers);

Maybe take a look at the mail() function at php.net 也许看看php.net的mail()函数

http://php.net/manual/en/function.mail.php http://php.net/manual/zh/function.mail.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM