【问题标题】:PHP mail function only can reply to Gmail account, but not for non-Gmail accountPHP邮件功能只能回复Gmail账号,不能回复非Gmail账号
【发布时间】:2015-11-06 21:41:13
【问题描述】:

用户在我的域中发布的邮件可以发送到我的网络邮箱,但随后用户无法收到我发送到他们电子邮件地址的邮件副本。除此之外,我的webmail可以回复邮件到用户的电子邮件地址,但只有gmail帐户可以在垃圾邮件文件夹中收到我的回复,但是yahoo和hotmail帐户没有收到我的webmail的任何回复消息。起初 yahoo 帐户仍然可以从 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>

【问题讨论】:

    标签: php function email


    【解决方案1】:

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

    我遇到了类似的问题。此错误可能来自多种原因:

    1) 如果您使用的是共享服务器,请咨询您的提供商,看看是否存在可能导致问题的原因,或者您是否有权发送电子邮件,显然您可以这样做。

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

    建议大家仔细阅读SMTP

    【讨论】:

    • 我没有使用 SMTP 插件。并且不使用共享服务器。还有什么其他原因导致了这个问题?
    • 检查您的服务器设置,看看这些端口是否被阻塞。否则,请与您的服务器提供商联系并询问该问题。
    猜你喜欢
    • 2018-06-22
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2012-06-26
    相关资源
    最近更新 更多