首页 > 解决方案 > 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";

它不再发送电子邮件。这里发生了什么问题?

标签: phpserver

解决方案


推荐阅读