1

我已将这两个文件上传到服务器,但是当我提交表单时,会收到感谢消息,但我的收件箱中没有邮件。请帮助我。

我的 HTML 页面是

<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">

</tr>





<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input  type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input  type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input  type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr> 
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input  type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
</td>
</tr>
</table>
</form>

我已将这两个文件上传到服务器,但是当我提交表单时,会收到感谢消息,但我的收件箱中没有邮件。请帮助我。

我的 PHP 编码是

<?php
if(isset($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW
    $email_to = "anshu_mah@yahoo.co.in";

    $email_subject = "website form submissions";


    function died($error) {
        // your error code can go here
        echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- place your own success html below -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
die();
?>
4

2 回答 2

0

邮件可能被您的传入服务器阻止,因为看起来发件人无效,这看起来类似于垃圾邮件。

如果您有权访问它,请检查服务器上的过滤器日志。这应该在 cPanel 中作为“跟踪电子邮件”提供。如果您的邮件被阻止,您将在列表中看到它并带有一个标记,表示有问题,将鼠标悬停在该标记上,您将看到原因。

如果是这种情况,并且原因类似于“发件人验证失败”,您可能想尝试-f“来自地址的信封”附加参数:

mail($email_to, $email_subject, $email_message, $headers, "-f $email_from");

邮件功能参考,包括关于“附加参数”的注释,专门-f针对 sendmail:

http://php.net/manual/en/function.mail.php

Additional_parameters 参数可用于将附加标志作为命令行选项传递给配置为在发送邮件时使用的程序,如 sendmail_path 配置设置所定义。例如,这可用于在使用带有 -f sendmail 选项的 sendmail 时设置信封发件人地址。

运行 Web 服务器的用户应作为受信任用户添加到 sendmail 配置中,以防止在使用此方法设置信封发件人 (-f) 时将“X-Warning”标头添加到邮件中。对于 sendmail 用户,此文件是 /etc/mail/trusted-users。

于 2013-02-05T11:17:16.753 回答
0

$email_to = 'nobody@example.com';

$email_subject = '主题';

$email_message = '你好';

$headers = '来自:webmaster@example.com' 。"\r\n" 。

'Reply-To: webmaster@example.com' . "\r\n" .

'X-Mailer: PHP/' . phpversion();

邮件($email_to,$email_subject,$email_message,$headers);

试试这个,让我知道

于 2013-02-05T11:18:29.063 回答