简体   繁体   English

在php邮件功能中我们可以将From属性设置为Word Not Email吗?

[英]in php mail function Can we set From attribute as a Word Not Email?

In php Mail Function, when we send headers, can we set the "From Mail" to be a Word like "Company Newsletter" Only, not in an email form as newsletter@company.com ?? 在php Mail Function中,当我们发送标题时,我们是否可以将“From Mail”设置为仅像“公司简报”这样的Word,而不是电子邮件形式的newsletter@company.com? how can we do that ? 我们怎么能这样做? because writing it is (not in an email form) prevents the email from being sent. 因为写它(不是电子邮件形式)会阻止发送电子邮件。

here's my code: 这是我的代码:

  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=windows-1256\r\n";

i have tried what tim suggested , having 我已经尝试了蒂姆建议的

  $row['SenderMail'] =  "Company Newsletter <Newsletter@ids.com.lb>";
  $headers .= "From:".$row['SenderMail']."\r\n"; 

  $subject=str_replace('%26','&',$row['Subject']);

  @mail($row['DestinationMail'], $subject, $row['Body'],$headers);

But still email isn't being sent.any help ? 但仍然没有发送电子邮件。任何帮助?

The following is a valid From: header - note the address is in angle brackets: 以下是有效的From:标题 - 请注意地址位于尖括号中:

"Company Newsletter <newsletter@company.com>"

Many email clients will simply show the Company Newsletter in the From column of the interface. 许多电子邮件客户端只会在界面的“发件人”列中显示公司简报。

Note that this is not allowed in the Return-Path: header, just the From: 请注意,在Return-Path:标题中不允许这样做,只有From:

Note 'display name' in RFC 2822 3.4 http://tools.ietf.org/html/rfc2822#section-3.4 注意RFC 2822中的“显示名称”3.4 http://tools.ietf.org/html/rfc2822#section-3.4

Please use the following : 请使用以下内容:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=windows-1256'."\r\n";
$headers .= 'To: '.$row['SenderMail'].' <'.$row['SenderMail'].'>'."\r\n";
$headers .= 'From: Company Newsletter <Newsletter@ids.com.lb>'."\r\n";

mail($row['DestinationMail'], $subject, $row['Body'], $headers);

That should do the trick ! 这应该够了吧 !

I've just rechecked and it's working with a basic example like : 我刚刚重新检查,它正在使用一个基本的例子,如:

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=windows-1256'."\r\n"; 
$headers .= 'To: Test <your@email.com>'."\r\n"; 
$headers .= 'From: Company Test <company@test.com>'."\r\n"; 

mail('Test <your@email.com>', 'test mail', 'test content', $headers);

Under which PHP version are you ? 你是哪个PHP版本的? Did you configure your mail server ? 你配置了邮件服务器吗? Can you please put these lines in top of your script : 你可以把这些行放在你的脚本之上:

ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT); 

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

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