我有我的活動頁面的PHP窗體。現在,它完美地發送給我自己,我可以將它CC給任何我喜歡的人沒有任何問題。但是,如果從我的表單上的下拉框中選擇了某個事件,我只想將其發送給特定的人員,並將其抄送給我。通過這種方式,舉辦活動的組織可以收到已完成表格的副本。如果可能的話,我還希望將自定義的消息發送給正在發送給它的人員。因此,例如:PHP如果值,那麼其他電子郵件?
如果填寫表單的人選擇的情況下,「心走,」然後表單結果應在「[email protected]」發送至「鮑勃」有消息說,「嗨鮑勃,你已經收到了一位新的志願者參加你的心臟行走活動,下面是一份註冊文件。「
當然,我得到一份副本。
我可以爲$ sendtoemail命令執行if/then語句或數組嗎?然後把以下內容複製給我:
$headers .= "Cc: [email protected]\r\n";
這樣做的最佳方法是什麼?謝謝你的幫助! :)
編輯:
這裏是我的代碼:
<?php
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
//send an email from the server TO YOUR EMAIL
$fromname = $_REQUEST['firstname'];
$fromemail = $_REQUEST['email'];
$subject = "NMVN EVENT REGISTRATION";
$message = " <b>EVENT:</b> ".$_REQUEST['pickevent'];
$message .= " <br><br> <b>First Name:</b> ".$_REQUEST['firstname'];
$message .= " <br> <b>Last Name:</b> ".$_REQUEST['lastname'];
$message .= " <br> <b>Cell Phone:</b> ".$_REQUEST['cellphone'];
$message .= " <br> <b>Alternative Phone:</b> ".$_REQUEST['altphone'];
//This is the person who is going to receive the email
$sendtoname = "Mike Gandy";
$sendtoemail = "[email protected]";
//Email header stuff
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromname <$fromemail>\r\n";
$headers .= "To: $sendtoname <$sendtoemail>\r\n";
$headers .= "Reply-To: $fromname <$fromemail>\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: Created by Mike Gandy";
//this next line creates and sends the email
mail($sendtoemail, $subject, $message, $headers);
?>
我在想更換此:
$sendtoname = "Mike Gandy";
$sendtoemail = "[email protected]";
有了這個:
if ($_REQUEST['pickevent'] == 'HeartWalk'))
//if "HeartWalk" is filled out, send to email
{
//send email
$sendtoname = "Bob";
$sendtoemail = "[email protected]";
}
elseif ($_REQUEST['pickevent'] == 'RaceCure'))
//if "RaceCure" is filled out, send to email
{
//send email
$sendtoname = "Susan";
$sendtoemail = "[email protected]";
}
elseif ($_REQUEST['pickevent'] == 'Bowling'))
//if "Bowling" is filled out, send to email
{
//send email
$sendtoname = "John";
$sendtoemail = "[email protected]";
}
但另外我需要選擇一個事件,所以「其他」將是一個彈出窗口,顯示「選擇一個事件!」。這有幫助嗎?
最後編輯時間:
好了,我得到了驗證工作。謝謝。我更換這樣的:
$sendtoname = "Mike Gandy";
$sendtoemail = "[email protected]";
有了這個:
switch(strtolower($event){
case 'HeartWalk':
$sendtoname('Bob')
$sendtoemail('[email protected]');
break;
case 'RaceCure':
$sendtoname('Susan')
$sendtoemail('[email protected]');
break;
case 'Bowling':
$sendtoname('John')
$sendtoemail('[email protected]');
break;
}
添加此:
$headers .= "Cc: [email protected]" . "\r\n";
而且改變了我的消息的開頭這樣:
$message = "Dear $sendtoname, <br><br>A new volunteer has registered for your "$_REQUEST['pickevent'];
$message .= " event. Below is a copy of their registration: ".$_REQUEST['blank'];
$message .= " <br><br> <b>First Name:</b> ".$_REQUEST['firstname'];
而且包括在我的形式:
<input type="hidden" name="blank" value="">
是嗎?沒有?
分享更大的代碼可能會給你更好的答案。 – 2013-04-11 15:43:19
是的,你也可以通過陣列來做到這一點..沒有使用開關.. – 2013-04-11 16:02:32