2014-05-07 126 views
-1

我剛剛繼承了一個PHP表單,我需要的是表單的提交者收到他們剛纔在字段中輸入的內容。這就是我所擁有的,不知道從哪裏開始。其他一切正常,我在收到郵件時收到郵件,我只是需要他們收到郵件的副本。自動回覆電子郵件給發件人/提交者

<?php 
// OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! 

$yourEmail = "[email protected]"; // the email address you wish to receive these mails through 
$yourWebsite = "Application"; // the name of your website 
$thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page 
$maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4 
$requiredFields = "name,lastname,email,Phone,ReferredBy";  // names of the fields you'd like to be required as a minimum, separate each field with a comma 

$textlink ='<a href="confirmation.html">Click Here And Take The Next Step</a>.' ; 
// DO NOT EDIT BELOW HERE 
$error_msg = array(); 
$result = null; 

$requiredFields = explode(",", $requiredFields); 

function clean($data) { 
$data = trim(stripslashes(strip_tags($data))); 
return $data; 
} 
function isBot() { 
$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz"); 

foreach ($bots as $bot) 
    if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) 
     return true; 

if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") 
    return true; 

return false; 
} 

    if ($_SERVER['REQUEST_METHOD'] == "POST") { 
if (isBot() !== false) 
    $error_msg[] = "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT']; 

// lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score.. 
// score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :) 
$points = (int)0; 

$badwords = array("javascript"); 

foreach ($badwords as $word) 
    if (
     strpos(strtolower($_POST['comments']), $word) !== false || 
     strpos(strtolower($_POST['name']), $word) !== false 
    ) 
     $points += 2; 

if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false) 
    $points += 2; 
if (isset($_POST['nojs'])) 
    $points += 1; 
if (preg_match("/(<.*>)/i", $_POST['comments'])) 
    $points += 2; 
if (strlen($_POST['name']) < 3) 
    $points += 1; 
if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) 
    $points += 2; 
if (preg_match("/[bcdfghjklmnpqrstvwxyz]{7,}/i", $_POST['comments'])) 
    $points += 1; 
// end score assignments 

foreach($requiredFields as $field) { 
    trim($_POST[$field]); 

    if (!isset($_POST[$field]) || empty($_POST[$field]) && array_pop($error_msg) != "Please fill in all the required fields and submit again.\r\n") 
     $error_msg[] = "Please fill in all the required fields and submit again."; 
} 

if (!empty($_POST['name']) && !preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) 
    $error_msg[] = "The name field must not contain special characters.\r\n"; 

if (!empty($_POST['email']) && !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) 
    $error_msg[] = "That is not a valid e-mail address.\r\n"; 



if ($error_msg == NULL && $points <= $maxPoints) { 
    $subject = "New Payment"; 

    $message = "Here is a new applicant: \n\n"; 
    foreach ($_POST as $key => $val) { 
     if (is_array($val)) { 
      foreach ($val as $subval) { 
       $message .= ucwords($key) . ": " . clean($subval) . "\r\n"; 
      } 
     } else { 
      $message .= ucwords($key) . ": " . clean($val) . "\r\n"; 
     } 
    } 
    $message .= "\r\n"; 

    // this means reply to the sender with e-mail and subject. 
    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { 
     $headers = "From: $yourEmail\r\n"; 
     $headers .= "Reply-To: {$_POST['email']}\r\n"; 
    } else { 
     $headers = "From: $yourWebsite <$yourEmail>\r\n"; 
     $headers .= "Reply-To: {$_POST['email']}\r\n"; 
    } 

    if (mail($yourEmail,$subject,$message,$headers)) { 
     if (!empty($thanksPage)) { 
      header("Location: $thanksPage"); 
      exit; 
     } else { 
      $result = 'Congratulations! We have received your application. IMPORTANT Click link below'; 

      $disable = true; 
     } 
    } else { 
     $error_msg[] = 'Your mail could not be sent this time. ['.$points.']'; 
    } 
} else { 
    if (empty($error_msg)) 
     $error_msg[] = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']'; 
} 
} 
function get_data($var) { 
if (isset($_POST[$var])) 
    echo htmlspecialchars($_POST[$var]); 
} 
    ?> 

感謝您的支持,現在又出現了另一個問題。

發件人必須收到收據中的這些字段,而不是所有這些字段,因爲我必須收到它們。 $ requiredFields =「名稱,姓氏,電子郵件,電話」有任何方式在if和elses中有這個?

所以在我收到的所有字段和發件人收到我們的4 5

回答

1

換句話說如何使用Cc: SMTP頭髮送的副本?

// this means reply to the sender with e-mail and subject. 
if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { 
    $headers = "From: $yourEmail\r\n"; 
    $headers .= "Cc: {$_POST['email']}\r\n"; 
    $headers .= "Reply-To: {$_POST['email']}\r\n"; 
} else { 
    $headers = "From: $yourWebsite <$yourEmail>\r\n"; 
    $headers .= "Cc: {$_POST['email']}\r\n"; 
    $headers .= "Reply-To: {$_POST['email']}\r\n"; 
} 

如果不希望用戶看到什麼解決郵件已發送的原始數據,可以執行以下操作:發送郵件主要是爲了用戶,而包括自己作爲一個blind carbon copy

// this means reply to the sender with e-mail and subject. 
if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { 
    $headers = "From: {$_POST['email']}\r\n"; 
    $headers .= "Bcc: $yourEmail\r\n"; 
    $headers .= "Reply-To: {$_POST['email']}\r\n"; 
} else { 
    $headers = "From: {$_POST['email']}\r\n"; 
    $headers .= "Bcc: $yourEmail\r\n"; 
    $headers .= "Reply-To: {$_POST['email']}\r\n"; 
} 

if (mail($_POST['email'],$subject,$message,$headers)) { 

但是,我不能保證你的服務器會接受用假髮送者發送郵件,也不能保證用戶的郵件服務器不會拒絕它。

+0

這個偉大的工程,發送者如何能見過誰所得到的電子郵件的人的電子郵件。如果我更改$ headers。=「Cc:{$ _POST ['email']} \ r \ n」; to $ headers。=「From:{$ _POST ['email']} \ r \ n」;它會起作用嗎? – user3202898

+0

我已經更新了我的答案。 – Martin

+0

謝謝您的回答,現在我有另一個問題,發件人必須收到收據中的這些字段,而不是所有這些字段,因爲我必須收到它們。 $ requiredFields =「名稱,姓氏,電子郵件,電話」有任何方式在if和elses中有這個? – user3202898

0

添加多個接收者爲逗號分隔字符串:

$yourEmail = "[email protected], [email protected]";  
mail($yourEmail,$subject,$message,$headers) 

$to = $_POST['email'] . ', ' . $yourEmail; 
mail($yourEmail,$subject,$message,$headers) 
+0

感謝,但只是將它發送到任何電子郵件我想,而不是形式的提交者。 – user3202898

+0

這是一個例子,表明您可以通過逗號分隔立即發送給多個地址。請不要吼我;) –

+0

好的,我看到了前兩行,idk我沒有看到其他兩個。我會把這個放在代碼的頂部?再次感謝。 – user3202898