如何通过PHP设置电子邮件发件人的名称? [英] How do I set the name of an email sender via PHP

查看:186
本文介绍了如何通过PHP设置电子邮件发件人的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当电子邮件打开时,我想从字段中的

So I want the from field when an email is opened to be something like

Jack Sparrow Via somesite而不是显式的电子邮件地址。

"Jack Sparrow Via somesite" as opposed to an explicit email address.

我想知道如何在PHP的 mail()函数中设置?

I wondering how to set this in PHP's mail() function?

推荐答案

您可以使用基本标题来实现此目的。

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);
?>

这篇关于如何通过PHP设置电子邮件发件人的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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