PHP mail()如何设置发件人邮件 [英] PHP mail() how to set sender mail
本文介绍了PHP mail()如何设置发件人邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
$to = 'to@mail.com';
$subject = 'test';
$body = 'test';
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "To: <$to>" . "\r\n";
$header .= 'From: from@mail.com \r\n';
mail($to, $subject, $body, $header);
代码有效,它发送电子邮件。
但是发件人不是我定义的发件人。
发件人似乎是网络邮件主机。
我在做什么错了?
The code works, it sends the email. But the sender is not the one that I defined. The sender seems to be the webmail host. What am I doing wrong?
推荐答案
尝试设置信封发件人,以及在标头中设置发件人消息,像这样:
Try setting the envelope sender, as well setting the sender in the headers of the message, like so:
$to = "to@to.com";
$from = "from@from.com";
$subject = "subject";
$message = "this is the message body";
$headers = "From: $from";
$ok = @mail($to, $subject, $message, $headers, "-f " . $from);
这篇关于PHP mail()如何设置发件人邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文