[英]How do I set the name of an email sender via PHP
So I want the from
field when an email is opened to be something like所以我想
from
外地当电子邮件被打开,是这样的
"Jack Sparrow Via somesite"
as opposed to an explicit email address. "Jack Sparrow Via somesite"
而不是明确的电子邮件地址。
I wondering how to set this in PHP's mail()
function?我想知道如何在 PHP 的
mail()
函数中设置它?
You can accomplish this by using basic headers.您可以通过使用基本标头来完成此操作。
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Jack Sparrow <jsparrow@blackpearl.com>' . PHP_EOL .
'Reply-To: Jack Sparrow <jsparrow@blackpearl.com>' . PHP_EOL .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
You have to set your headers:你必须设置你的标题:
$to = "Someone@email.com";
$header = "FROM: Jack Sparrow <some@site.com>\r\n";
$message = "Your message here.";
$subject = "Your subject";
mail($to,$subject,$message,$header) or die();
just use like this就这样使用
$headers .= 'From: [Name of the person]'.'<'. $this->from .'>'. "\n";
in Header Section.在标题部分。
如果您使用来自 GitHub 的 PHP Mailer,那么您可以通过以下方式进行:
$mail->SetFrom("info@mibckerala.org", "MIBC");
$to = "Someone@email.com";
$message = "Your message here.";
$subject = "Your subject";
mail($to,$subject,$message,$header, '-f some@site.com -F "Jack Sparrow"') or die();
Just add the -f parameter to provide the sender's email and -F parameter to provide the sender's name to the mail(), all as a string.只需添加 -f 参数以提供发件人的电子邮件和 -F 参数以将发件人的姓名提供给 mail(),所有这些都是字符串。
Note: double quotes around "Jack Sparrow"注意: “Jack Sparrow”周围的双引号
Assuming that you are using sendmail on a Linux machine:假设您在 Linux 机器上使用 sendmail:
You can find more detailed information by typing "man sendmail" in your shell.您可以通过在 shell 中键入“man sendmail”来找到更多详细信息。
I am not sure exactly what you mean, but as you can see on PHP.net mail function .我不确定你的意思,但正如你在PHP.net mail function上看到的那样。
To add the name to the from section you need to send this in the headers.要将名称添加到 from 部分,您需要在标题中发送它。
From:Name<email@example.com>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.