0

这是我的代码和我的表单......它就像电子邮件已发送一样,但它从未到达。

我想知道可能出了什么问题……有人吗?

该网站托管在 Linux 服务器上,我真的不知道服务器是否会因为某种不兼容而阻止电子邮件......我真的不知道它可能是什么。

<?php
if($_POST)
{
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
    die();
} 

$to_Email       = "myemail@gmail.com"; //Replace with recipient email address
$subject        = 'Ah!! My email from Somebody out there...'; //Subject line for emails

//check $_POST vars are set, exit if any missing
if(!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userPhone"]) || !isset($_POST["userMessage"]))
{
    die();
}

//Sanitize input data using PHP filter_var().
$user_Name        = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
$user_Email       = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
$user_Phone       = filter_var($_POST["userPhone"], FILTER_SANITIZE_STRING);
$user_Message     = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);

//additional php validation
if(strlen($user_Name)<4) // If length is less than 4 it will throw an HTTP error.
{
    header('HTTP/1.1 500 Name is too short or empty!');
    exit();
}
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
    header('HTTP/1.1 500 Please enter a valid email!');
    exit();
}
if(!is_numeric($user_Phone)) //check entered data is numbers
{
    header('HTTP/1.1 500 Only numbers allowed in phone field');
    exit();
}
if(strlen($user_Message)<5) //check emtpy message
{
    header('HTTP/1.1 500 Too short message! Please enter something.');
    exit();
}

//proceed with PHP email.
$headers = 'From: '.$user_Email.'' . "rn" .
'Reply-To: '.$user_Email.'' . "rn" .
'X-Mailer: PHP/' . phpversion();

@$sentMail = mail($to_Email, $subject, $user_Message .'  -'.$user_Name, $headers);

if(!$sentMail)
{
    header('HTTP/1.1 500 Couldnot send mail! Sorry..');
    exit();
}else{
    echo 'Hi '.$user_Name .', Thank you for your email! ';
    echo 'Your email has already arrived in my Inbox, all I need to do is Check it.';
}
 }
?> 

这是我的表格:

<fieldset id="contact_form">
<legend>My Contact Form</legend>
    <div id="result"></div>
    <input type="text" name="name" id="inputt" placeholder="Enter Your Name" />


   <input type="text" name="email" id="inputt" placeholder="Enter Your Email" />


    <input type="text" name="phone" id="inputt" placeholder="Phone Number" />


    <textarea name="message" id="message" placeholder="Enter Your Name"></textarea>


   <button class="submit_btn" id="submit_btn">Submit</button>

</fieldset>
4

2 回答 2

0

$headers错了,你追加"rn"而不是"\r\n". 试试这个:

$headers = 'From: '.$user_Email. "\r\n" .
'Reply-To: '.$user_Email. "\r\n" .
'X-Mailer: PHP/' . phpversion();
于 2013-05-04T09:15:21.550 回答
0

根据您在邮件日志中的评论,您需要调整 php.ini 以将--r参数包含到您的sendmail_path.

默认情况下,它通常是:

sendmail_path = /usr/sbin/sendmail -t -i

显然,您正在使用另一个也需要 --r 参数的参数。将其附加到您的 sendmail_path 应该有很长的路要走。

于 2013-05-04T09:25:45.423 回答