PHP代码有效,但未显示谁是发件人。仅显示noreply@example.com

时间:2019-04-09 15:03:57

标签: php

我的用于发送电子邮件的PHP代码可以正常工作,但是有一个问题并未显示谁是发件人,而是显示了noreply@example.com。我将网站托管在ecowebhosting。

<?php

 $error = "";
 $successMessage = "";
    if ($_POST) {        
        if (!$_POST["email"]) {            
            $error .= "An email address is required.<br>";            
        }        
        if (!$_POST["message"]) {            
            $error .= "The message field is required.<br>";            
        }        
        if (!$_POST["subject"]) {            
            $error .= "The subject is required.<br>";            
        }        
        if ($_POST['email'] && filter_var($_POST["email"], FILTER_VALIDATE_EMAIL) === false) {            
            $error .= "The email address is invalid.<br>";            
        }        
        if ($error != "") {            
            $error = '<div><p>There were error(s) in your form:</p>' . $error . '</div>';            
        } else {

            $to = "example@gmail.com"; 
            $subject = $_POST['subject'];            
            $message = $_POST['message'];

            $headers = "MIME-VERSION: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            $headers = "From: ".$_POST['email'] . "\r\n";
                $headers = "Reply-To: ".$_POST['email'] . "\r\n";
            $headers = "Subject: ".$_POST['subject'] . "\r\n";
                $headers = "Message : ".$_POST['message'] . "\r\n";  

            if (mail($to, $subject, $message, $headers)) {                
              echo  $successMessage = '<div>Your message was sent, we\'ll get back to you ASAP!</div>';   
            } else {                
               echo $error = '<div><p><strong>Your message couldn\'t be sent - please try again later</div>';                            
            }            
        }                  
    }   
?>

0 个答案:

没有答案