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

时间:2015-11-06 13:20:34

标签: php function email

我域中发布的用户邮件可以发送到我的网络邮箱,但是用户无法收到用户发送到其电子邮件地址的邮件副本。除此之外,我的网络邮件可以回复用户的电子邮件地址的消息,但只有gmail帐户可以在垃圾邮件文件夹中收到我的回复,但雅虎和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>

1 个答案:

答案 0 :(得分:0)

您的代码看起来很好,不知道我们在include(“functions / functions.php”)中有什么内容;

我有类似的问题。此错误可能有多种原因:

1)如果您正在使用共享服务器检查您的提供商,看看是否有可能导致问题的事情,或者即使您有权发送电子邮件,显然也可以。

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

我建议您仔细阅读SMTP