PHP邮件功能只能回复Gmail帐户,但不能回复非Gmail帐户


PHP mail function only can reply to Gmail account, but not for non-Gmail account

用户在我的域中发布的消息可以发送到我的网络邮件,但用户无法收到用户发送到其电子邮件地址的消息的副本。除此之外,我的webmail可以回复用户的电子邮件地址,但只有gmail帐户可以在垃圾邮件文件夹中收到我的回复,而yahoo和hotmail帐户没有收到任何来自我webmail的回复消息。起初,雅虎帐户仍然可以接收来自网络邮件的消息副本和回复消息。但现在完全不行了。我能知道出了什么问题吗?谢谢你的好心帮助!

<?php
 session_start();
 include("functions/functions.php");
?>
<?php 
if(isset($_POST['submit'])){
    $ip = getIP();
    $userName= $_POST['userName'];
    $phoneNumber= $_POST['phoneNumber'];
    $email= $_POST['email'];
    $message= $_POST['message'];
    $currentdatetime=date('Y-m-d');
if(empty($userName)||empty($phoneNumber)||empty($email)||empty($message))
    {
        echo "<script type='text/javascript'>alert('All the fields must be filled in. Please try again.');";
 echo  "window.location.href='contact.php';";
 echo"</script>";
 exit();
    }
    else if (ctype_alpha(str_replace(' ', '', $userName)) === false) {
        echo "<script type='text/javascript'>alert('Name must only contain letters!');";
 echo  "window.location.href='contact.php';";
 echo"</script>";
 exit();
}

    else if(strlen($phoneNumber)<11 || strlen($phoneNumber)>12|| substr($phoneNumber, 3, 1)!='-')
    {
        echo "<script type='text/javascript'>alert('Phone Format is incorrect. Please use the following format: 01x-1234567');";
 echo  "window.location.href='contact.php';";
 echo"</script>";
 exit();
    }
    else if((strpos("$email","@")== 0)||  (strpos("$email",".com")== 0) )
    {
        echo "<script type='text/javascript'>alert('Email Format is incorrect.');";
 echo  "window.location.href='contact.php';";
 echo"</script>";
 exit();
 }
 else if($_POST['userName']!=''&& $_POST['phoneNumber']!='' && $_POST['email']!='' && $_POST['message']!='' ){

$to = "email@site.com"; // this is my Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['userName'];
$contact = $_POST['phoneNumber'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message ="Dear Sir/Madam,". "'n'n" ."New enquiry as below:" . "'n'n" ."Name:" .$name . "'n'n" . "Contact No: " . $contact. "'n'n" ."Email Address:". $from. "'n'n" ."Message/Enquiry:". $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "'n'n" . $_POST['message'];
$headers = "MIME-Version: 1.0" . "'r'n";
$headers .= "Content-type:text/html;charset=UTF-8" . "'r'n";
$headers2 = "MIME-Version: 1.0" . "'r'n";
$headers2 .= "Content-type:text/html;charset=UTF-8" . "'r'n";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "<script>alert('Mail Sent. Thank you " . $name . ", we will contact you shortly.')</script>";
}
//insert into databse
$insert_msg = "insert into msg(userName, phoneNumber, email, message, status, msg_date) values ('$userName', '$phoneNumber', '$email', '$message', 'Pending', '$currentdatetime')";
    $run_msg = mysqli_query($con, $insert_msg);
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body> 
  <!--start-contact-->
  <div class="contact">
    <div class="container">
    <h3>CONTACT US</h3>
    <p>Please contact us for all inquiries and purchase options.</p>
    <form action='' method='POST'>
         <input type="text" name='userName' placeholder="NAME" required>
         <input type="text" name='phoneNumber' placeholder="PHONE NUMBER" required>          
         <input class='user' name='email' type="text" placeholder="EMAIL" required><br>
         <textarea name='message' placeholder="MESSAGE"></textarea>
         <input type="submit" name="submit" value="SEND">
    </form>
   </div>
   </div>
   <!--end-contact-->
 </body>
 </html>

您的代码看起来很好,但不知道include("functions/functions.php")中有什么;

我也有类似的问题。这种错误可能来自多种原因:

1) 如果你正在使用共享服务器,请与你的提供商核实是否有可能导致问题的原因,或者你是否有权发送电子邮件,显然你有

2) 如果使用SMTP插件,请检查端口25、587、465、475和2525是否未被阻止。这些端口是hotmail和其他公司用来处理电子邮件流量的端口,如果出于某种原因,您的脚本不包括这些端口,或者出于安全原因,它阻止了它们,您的电子邮件就会出现问题。

我建议您仔细阅读SMTP