联系表格php | EmailFrom和Bcc未显示。

时间:2015-07-14 12:06:11

标签: php forms email contact cc

我是一个新的PHP,所以我需要一些帮助,并在其他地方没有运气。

我正在尝试将提交电子邮件的人作为发件人,例如当电子邮件通过它时显示为(未知发件人)或者通过服务器作为" testserver"。我希望在收件箱中未打开时,将其发送到他们的电子邮件地址。这样客户端只需单击回复即可,无需选择电子邮件地址。

我在设置cc和bcc字段时也遇到了问题。

任何想法都将受到高度赞赏。

继承人html



  <form  method="post" id="myform" name="myform">
        <table width="250" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>Name:</td>
            <td> <input type="text" name="name" id="name"></td>
            </tr>
          <tr>
            <td>Number:</td>
            <td><input type="text" name="number" id="number"></td>
            </tr>
          <tr>
            <td><label for="email">Email:</label></td>
            <td><input type="text" name="email" id="email"></td>
            </tr>
         
                     <tr>
            <td><label for="subject">Subject:</label></td>
            <td><input type="text" name="subject" id="subject" required></td>
            </tr>
                      <tr>
            <td><label for="comment">Comment:</label></td>
            <td>&nbsp;</td>
            </tr>
                      <tr>
            <td>&nbsp;</td>
            <td><textarea name="comment" id="comment" cols="45" rows="5"></textarea></td>
            </tr>
                     <tr>
            <td colspan="2">Please answer the question below</td>
            </tr>
            
        
          <tr>
          <td> <?
if (isset($_POST['qcChosenOne']))
{
      $captchaEquations = array(
                              0=>array('1 + 6',7),
                              1=>array('8 - 3',5),
                              2=>array('15 + 2',17),
                              3=>array('8 + 2',10),
                              4=>array('10 - 5',5),
                         );

     $qcChosen = $_POST['qcChosenOne'];
     $qcGivenAnswer = (int) trim($_POST['qcQuestion']);
     $qcAnswer = (int) $captchaEquations[$qcChosen][1];
     unset($_POST['qcChosenOne'],$_POST['qcQuestion']);	
     if ($qcGivenAnswer ==  $qcAnswer)
	 include('contact.php');
     else
	  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";

}
 ?>
 &#49;&#48;&#32;&#45;&#32;&#53;&#32;&#61;&#32; </td>
           <td><input name="qcQuestion" type="text" class="form_fields" id="Captcha" />
                                  <input type="hidden" name="qcChosenOne" value="4" /></td>
           </tr>
          <tr>
         
          <td>&nbsp;</td>
           <td><input type="submit" name="submit" id="submit" value="Submit"></td>
          </tr>
        </table>
       </form>
        
 <script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("Name","req","Please enter your name");
frmvalidator.addValidation("Tel","req","Please enter your telephone number");
frmvalidator.addValidation("Email","req","Please enter email");
frmvalidator.addValidation("Email","email","Please provide a valid email address");
frmvalidator.addValidation("City","req","Please enter your City");
frmvalidator.addValidation("Make","req","Please enter the Make");
frmvalidator.addValidation("Model","req","Please enter your Model");
frmvalidator.addValidation("Enquiry","req","Please enter your enquiry/comments");
frmvalidator.addValidation("Captcha","req","Please enter the answer to the simple calculation. This is to ensure you are not a SPAM crawler.");
</script> 
        
&#13;
&#13;
&#13;

继承人的PHP

&#13;
&#13;
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$EmailFrom = Trim(stripslashes($_POST['email'])); 
$EmailTo = "dalevanm@gmail.com";
$Subject = "Name, Website Enquiry Form";
$name = Trim(stripslashes($_POST['name'])); 
$number = Trim(stripslashes($_POST['number'])); 
$email = Trim(stripslashes($_POST['email'])); 
$subject = Trim(stripslashes($_POST['subject'])); 
$comment = Trim(stripslashes($_POST['comment'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Number: ";
$Body .= $number;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $subject;
$Body .= "\n";
$Body .= "Comment: ";
$Body .= $comment;
$Body .= "\n";

 $headers .=  "\r\n".'Cc: dalevanm@gmail.com' . "\r\n";


// send email 
$success = mail($EmailTo, $Subject, $Body, $EmailFrom, $header);

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=_confirmation_enquiry.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
}
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

发送电子邮件时:

$success = mail($EmailTo, $Subject, $Body, $EmailFrom, $header);

您从未定义过名为$header的变量。你几乎在这里定义了一个名为$headers的人:

$headers .=  "\r\n".'Cc: dalevanm@gmail.com' . "\r\n";

但我怀疑使用.=运算符也可能失败,因为变量不存在。只需直接分配:

$headers =  "\r\n".'Cc: dalevanm@gmail.com' . "\r\n";

并使用该变量:

$success = mail($EmailTo, $Subject, $Body, $EmailFrom, $headers);