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页面我上面的问题反映了你的建议......看起来是否正确? –