加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP mail()如何设置发件人邮件

发布时间:2020-12-13 13:49:17 所属栏目:PHP教程 来源:网络整理
导读:这是我的代码: $to = 'to@mail.com';$subject = 'test';$body = 'test';$header = 'MIME-Version: 1.0' . "rn";$header .= 'Content-type: text/html; charset=iso-8859-1' . "rn";$header .= "To: $to" . "rn";$header .= 'From: from@mail.com rn
这是我的代码:
$to = 'to@mail.com';

$subject = 'test';

$body = 'test';

$header  = 'MIME-Version: 1.0' . "rn";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$header .= "To: <$to>" . "rn";
$header .= 'From: from@mail.com rn';

mail($to,$subject,$body,$header);

代码有效,它会发送电子邮件.
但发件人不是我定义的那个.
发件人似乎是网络邮件主机.
我究竟做错了什么?

尝试设置信封发件人,并在邮件标题中设置发件人,如下所示:
$to = "to@to.com";
$from = "from@from.com";
$subject = "subject";
$message = "this is the message body";

$headers = "From: $from"; 
$ok = @mail($to,$message,$headers,"-f " . $from);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读