简体   繁体   English

我的联系表格未发送邮件

[英]My Contact Form is not sending Mail

I have uploded both files to server but when i submit a form the thanks message comes but there no mail in my inbox. 我已经将两个文件都上传到服务器,但是当我提交表单时,会出现感谢消息,但是收件箱中没有邮件。 plz help me. 请帮助我。

My Html Page is 我的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>

I have uploded both files to server but when i submit a form the thanks message comes but there no mail in my inbox. 我已经将两个文件都上传到服务器,但是当我提交表单时,会出现感谢消息,但是收件箱中没有邮件。 plz help me. 请帮助我。

My Php Coding Is 我的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();
?>

It is possible that the mail is getting blocked by your incoming server because it looks like the sender is invalid, which appears similar to spam. 邮件可能被您的传入服务器阻止,因为它看起来发件人无效,这看起来类似于垃圾邮件。

If you have access to it, check the filter log on your server. 如果可以访问它,请检查服务器上的筛选器日志。 This should be available in cPanel as "trace email". 这应该在cPanel中作为“跟踪电子邮件”提供。 If your mail is getting blocked you will see it in the list with a mark against it that indicates a problem, hover over that and you will see the reason. 如果您的邮件被阻止,您将在列表中看到该邮件,并在其上标记一个表明有问题的标记,将鼠标悬停在该邮件上,您会看到原因。

If that is the case, and the reason is something like "sender verification failed", y ou might like to try the -f "envelope from address" additional parameter: 如果是这种情况,并且原因类似于“发件人验证失败”,则您可能要尝试使用-f “来自地址的信封”附加参数:

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

Mail function reference, including note about "additional parameters" and specifically -f for sendmail: 邮件功能参考,包括有关“附加参数”的注释,特别是-f代表sendmail:

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

The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. add_parameters参数可用于将其他标志作为命令行选项传递到配置为发送邮件时使用的程序,如sendmail_path配置设置所定义。 For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option. 例如,当将sendmail与-f sendmail选项一起使用时,可用于设置信封发件人地址。

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. 使用此方法设置信封发件人(-f)时,应将运行Web服务器的用户作为受信任的用户添加为sendmail配置,以防止将“ X警告”标头添加到邮件中。 For sendmail users, this file is /etc/mail/trusted-users. 对于sendmail用户,此文件为/ etc / mail / trusted-users。

$email_to = 'nobody@example.com'; $ email_to ='nobody@example.com';

$email_subject = 'the subject'; $ email_subject ='主题';

$email_message = 'hello'; $ email_message ='你好';

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

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

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

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

Try this and let me know 试试这个,让我知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM