php - PHP邮件标头中的发件人和返回路径不起作用
问题描述
我有一个结构简单的表单,用户可以通过它向我发送邮件。到目前为止,我的代码一直在工作,但问题是如果我将标题更改为显示电子邮件用户而不是我的,它就不起作用。
我的代码:
<?php
if(isset($_POST['submit'])) {
$to = 'noreply@example.com'; //email that will be sent the message
$subject = 'Mail';
$name = $_POST['name'];
$email_sender = $_POST['email'];
$message= $_POST['message'];
$telephone = $_POST['telephone'];
$headers = "MIME-Version: 1.1\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: noreply@example.com\r\n";
$header.= "Return-Path: noreply@example.com\r\n";
$envio = mail($to,$subject,$message,$headers);
if($envio) {
header('Location: http://website.com');
}
else {
header('Location: /index.html#contact');
}
}
?>
如果我将“From”和“Return-Path”中的标题更改为以下内容:
$headers .= "From:" .$email_sender. "\r\n";
$headers.= "Return-Path:" .$email_sender. "\r\n";
它不再发送电子邮件。这里发生了什么问题?
解决方案
推荐阅读
- oracle - 如何在 Spring Boot 中为两个过程使用相同的数据库会话
- git - 相同更改的 git merge -> 使 git blame 以合并的提交为目标
- scala - Akka Streams RestartSource.onFailuresWithBackoff 停止条件
- discord - 因为我在欢迎信息中有这个问题
- java - 使用 mssp 将数字签名附加到 pdf
- android - 如何在反应原生博览会中将文件上传到服务器
- android - 在 Visual Studio 中使用 ionic + Cordova 我不断收到“未找到已安装的构建工具。安装 Android 构建工具版本 19.1.0 或更高版本。”
- google-apps-script - 无法从 Google App Scripts 打开 Slack 模式
- c++ - 嵌套 QGraphicsScenes 中的选择排除
- javascript - 在 react-native 中使用 javascript 插件时面临的问题