0
這是我第一次設置電子郵件表單。使用可選收件人創建電子郵件表格
到目前爲止,我一直沒有運氣讓它工作。
我已經創建了一個非常簡潔的窗體演示(和php頁面),以包含在我的問題中。
如果有人能幫我弄清楚我做錯了什麼,那將不勝感激。
*注意:像這個演示一樣....我的表單也有多個接收者選項。
形式:
<html>
<head>
<script>
function onBlur(el) {if (el.value == '') {el.value = el.defaultValue;}}
function onFocus(el) {if (el.value == el.defaultValue) {el.value = '';}}
</script>
<style>
body{margin-left:20px; margin-top:30px; font-family:Arial, Helvetica, sans-serif; font-size:12pt;}
.header{font-size:20pt; margin-bottom:10px;}
.field{display:block; margin-bottom:10px; width:200px;}
.subjectTitle{margin-top:20px;}
.subject{width:500px; margin-bottom:10px;}
.messageTitle{margin-top:10px; margin-bottom:4px;}
.textarea{width:500px; height:200; display:block;}
.recipient{margin-top:20px;}
.recipient a{display:block; margin-bottom:4px;}
.sendBtn{margin-top:30px;}
</style>
</head>
<body>
<div class="header">EMAIL FORM</div>
<form method="post" action="emailFormHandler.php">
<input class="field" name="firstName" type="text" value="First Name" onBlur="onBlur(this)" onFocus="onFocus(this)">
<input class="field" name="lastName" type="text" value="Last Name" onBlur="onBlur(this)" onFocus="onFocus(this)">
<input class="field" name="emailAddress" type="text" value="Email Address" onBlur="onBlur(this)" onFocus="onFocus(this)">
<div class="subjectTitle">Subject</div>
<input class="subject" name="subject" type="text">
<div class="messageTitle">Message</div>
<textarea class="textarea" name="message"></textarea>
<div class="recipient">
<a>Recipient</a>
<select class="field" name="recipient">
<option value="[email protected]">Management</option>
<option value="[email protected]">Accounting</option>
</select>
</div>
<input class="sendBtn" type="submit" name="sendBtn" value="Send Email">
</button>
</form>
</body>
</html>
PHP頁面:(emailFormHandler.php)
<html>
<head>
</head>
<body>
<?php
$subject=$_REQUEST['subject'];
$message=$_REQUEST['message'];
$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];
$email=$_REQUEST['email'];
$headers="From: $email";
$recipient = [$to,'[email protected]', '[email protected]'];
$sent=mail(implode(',',$recipient),$subject,$message,$headers);
if($sent){print ('<a>Your Message Has Been Sent</a>');}
else {print "Sorry, we encountered a problem.<br>Your email was not sent.<br>Please try again later.";}
?>
</div>
</body>
</html>
我還沒有拿到形式在所有的工作,有或沒有多個收件人下拉。我嘗試了兩個。所以我明顯需要一些關於整個情況的建議。
佰仁堅持......應該是什麼我用$來衡量價值嗎? –
如果你有一個地址列表發送到'$ listOfRecipients = [$ to,'[email protected]'];' –
Nigel Ren .... OK,所以,我編輯了窗體和PHP頁面我上面的問題反映了你的建議......看起來是否正確? –