联系表单不发送发件人电子邮件地址 [英] Contact Form not sending senders email address

查看:83
本文介绍了联系表单不发送发件人电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我不知道这是否是一个常见的问题,但我似乎无法理解为什么会这样。

我正在尝试处理表单并让它将详细信息发送到电子邮件。很简单。

这是它的PHP代码。当某人填写表格时,它会显示除发件人电子邮件之外的所有内容。它作为未知发件人出现。有谁知道我怎么解决它?

非常感谢任何花时间看这个的人。



- 更新问题







PHP验证



 <?php  

if(isset($ _ POST [' email'])){



// 根据需要编辑2条线

$ email_to = you@yourdomain.com;

$ email_subject = 您的电子邮件主题行;





函数死亡($ error){

/ / 您的错误代码可以在这里

echo 我们非常抱歉,但您提交的表单中发现了错误。;

echo 这些错误出现在下面。< br />< br />;

echo $ error。 < br />< br />;

echo 请转到返回并修复这些错误。< br />< br />;

die();

}



// 验证预期数据存在

if(!isset($ _ POST [' first_name'])||

!isset($ _ POST [' last_name '])||

!isset($ _ POST [' email' ])||

!isset($ _ POST [' telephone'])||

!isset($ _ POST [' comments'])){

死亡(' 我们很抱歉,但似乎有您提交的表单存在问题。');

}



$ first_name = $ _POST [' first_name']; // required

$ last_name = $ _POST [' last_name']; // required

$ email_from = $ _POST [' email']; // required

$电话 = $ _POST [' telephone']; // 不需要

$ 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 。= ' 您输入的电子邮件地址似乎无效。< br />';

}

$ string_exp = < span class =code-string> / ^ [A-Za-z .'-] + $ /;

if(!preg_match($ string_exp,$ first_name)){

$ error_message 。= ' 您输入的名字似乎无效。< br />';

}

if(!preg_match($ string_exp,$ last_name)){

$ error_message 。= ' 您输入的姓氏似乎无效。< br />' ;

}

if(strlen($ comments)< 2){

$ error_message 。= ' 您输入的评论似乎无效。< br />';

}

if(strlen($ error_message)> 0){

death($ error_message);

}

$ email_message = < span class =code-string>下面的表单详细信息。\ nn \ n
;



函数clean_string($ string){

$ bad = array( content-type < span class =code-string> bcc:
to: cc: HREF);

return str_replace($ bad, ,$字符串);

}



$ email_message 。= 名字: .clean_string($ first_name)。 \\\
;

$ email_message 。= 姓氏: .clean_string($ last_name)。 \ n;

$ email_message 。= 电子邮件: .clean_string($ email_from)。 \ n;

$ email_message 。= 电话: .clean_string($ telephone)。 \ n;

$ email_message 。= 评论: .clean_string($ comments)。 \ n;





// 创建电子邮件标题

$ headers = ' From:'。$ email_from。 \\\\ n

' 回复:'。$ email_from。 \\\\ n

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

@mail($ email_to,$ email_subject,$ email_message,$ headers);

?>



<! - 在此处包含您自己的成功HTML - >



感谢您与我们联系。我们会尽快与您联系。



<? php

}

?>

解决方案

_POST [' email'])){



// 根据需要编辑2条线


email_to = you@yourdomain.com;


email_subject = 您的电子邮件主题行;





函数死亡(


HEllo everyone, i don't know if this is a common problem but i can't seem to understand why it is happening.
I am trying to process a form and have it send the details to an email. Simple enough.
Here is the PHP code for it. When someone fills the form up it shows everything except the senders email. It comes out as unknown sender. Does anyone know how i can fix it?
Thanks a lot to anyone who takes time out to look at this.

--Updated question



PHP validation

<?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "you@yourdomain.com";
 
    $email_subject = "Your email subject line";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<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);  
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Thank you for contacting us. We will be in touch with you very soon.
 
 
 
<?php
 
}
 
?>

解决方案

_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED


email_to = "you@yourdomain.com";


email_subject = "Your email subject line"; function died(


这篇关于联系表单不发送发件人电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆