2010-09-18 80 views
0

我有一個html表格鏈接到一個PHP電子郵件。表單運行良好,但我無法通過Cc和密件抄送。PHP形式審查 - 抄送和密件抄送不起作用

這是整個代碼。請檢查並幫助我瞭解我在標題中的抄送和密件抄送部分出錯。

感謝:

<?php 
    $emailFromName = $_POST['name']; 
    $emailFrom = $_POST['email']; 
    $emailFromPhone = $_POST['phone']; 
    $email9_11 = $_POST['9-10']; 
    $email10_11 = $_POST['10-11']; 
    $email11_12 = $_POST['11-12']; 
    $email12_1 = $_POST['12-1']; 

    if (empty($emailFromName)) { 
     echo 'Please enter your name.'; 
    } elseif (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) { 
     echo 'The email address entered is invalid.'; 
    } else { 

     $emailTo = "[email protected]" ; 
     $subject = "Family History Conference Registration"; 


     if (!empty($emailFrom)) { 
    $headers = 'From: "' . $emailFromName . '" <' . $emailFrom . '>'; 
     } else { 
      $headers = 'From: Family History Conference <[email protected]>' . "\r\n"; 
      $headers .= 'Cc: $emailFrom' . "\r\n"; 
      $headers .= 'Bcc: [email protected]' . "\r\n"; 
     } 

     $body = "From: ".$emailFromName."\n"; 
     $body .= "Email: ".$emailFrom."\n"; 
     $body .= "Phone: ".$emailFromPhone."\n\n"; 
     $body .= "I would like to attend the following classes.\n"; 
     $body .= "9:10 to 10:00: ".$email9_11."\n"; 
     $body .= "10:10 to 11:00: ".$email10_11."\n"; 
     $body .= "11:10 to 12:00: ".$email11_12."\n"; 
     $body .= "12:10 to 1:00: ".$email12_1."\n"; 

     /* Send Email */ 
     if (mail($emailTo, $subject, $body, $headers)) { 
      echo "<h2>Thank you for Registering</h2> 
      <h3>You have registered for the following classes</h3> 
      <p>9:10 to 10:00am: \"$email9_11\" <br /> 
      10:10 to 11:00am: \"$email10_11\"<br /> 
      11:10 to 12:00: \"$email11_12\"<br /> 
      12:10 to 1:00: \"$email12_1\"</p> 
     <p>We look forward to seeing you October 31, 2010</p>"; 


     } else { 
      echo 'There was an internal error while sending your email.<br>'; 
      echo 'Please try again later.';  
     } 
    } 
?> 
+0

你這是什麼意思是「不通過」?你的意思是當你收到郵件時你看不到標題,或者它沒有發送電子郵件到CC'd地址? – NullUserException 2010-09-18 18:46:04

+0

它不會將電子郵件發送給cc和密件抄送收件人。 – fmz 2010-09-18 19:05:45

回答

1

您使用單引號

$headers .= 'Cc: $emailFrom' . "\r\n"; 

PHP不會解釋變量單引號內,你必須用雙引號

$headers .= "Cc: $emailFrom\r\n"; 
+0

我添加了雙引號,但仍然沒有收到電子郵件。我錯過了別的東西嗎? – fmz 2010-09-18 19:07:30

相關問題