我的发送联系人 php 文件有问题。我希望根据访客选择的主题发送电子邮件,例如:Padicure Booking 主题电子邮件将发送至 booking@example.com,而一般查询主题将发送至 info@example.com
下面是我的php代码。
<?php
function emailswitch( $key ) {
$to = array(
'Pedicure Price Inquiry' => 'enquiry@gmail.com',
'Manicure Price Inquiry' => 'enquiry@gmail.com',
'Booking Time' => 'info@gmail.com'
);
$default = 'info@gmail.com';
return isset( $_POST['field_?'] ) && !empty($to[ $_POST['field_?'] ]) ? $to[ $_POST['field_?'] ]: $default; $from = $_POST['email'];
}
$from_name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['category'];
// collect data
$body = "";
foreach($_POST as $key => $val)
{
if($key != 'captcha')
$body .= ucfirst($key).": ".$val."\r\n";
}
// construct MIME PLAIN Email headers
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=utf-8\n";
$header .= "From: $from_name <$email> \r\nReply-To: $from_name <$email> \r\nReturn-Path: <$email> \r\n";
// send email
$to = emailswitch( $subject );
$mail_sent = mail($to, $subject, $body, $header);
?>
以下是我的表单代码:
<div id="contact_form">
<form action="sendContact.php" method="post" onsubmit="return sendContact();">
<p><label id="lname" for="name">Full name:</label>
<input id="name" class="text" name="name" onblur="input_blur('name');" onfocus="input_focus('name');" type="text" /></p>
<p><label id="lemail" for="email">Email address:</label>
<input id="email" class="text" name="email" onblur="input_blur('email');" onfocus="input_focus('email');" type="text" /></p>
<div class="x"></div>
<p id="email-error" class="error">You must enter your email address!</p>
<p><label id="lcategory" for="category">Category:</label>
<select id="category" name="category" onblur="input_blur('category');" onfocus="input_focus('category');">
<option value="Pedicure Price Inquiry">Pedicure Price Inquiry</option>
<option value="Manicure Price Inquiry">Manicure Price Inquiry</option>
<option value="Booking Time">Booking Time</option></select></p>
<p><label id="lmessage" for="message">Message:</label>
<textarea id="message" name="message" onblur="input_blur('message');" onfocus="input_focus('message');" rows="" cols=""></textarea></p>
<div class="x"></div>
<p id="message-error" class="error">You must enter your message!</p>
<p><label id="lcaptcha" for="captcha"></label>
<input id="captcha" class="text" name="captcha" onblur="input_blur('captcha');" onfocus="input_focus('captcha');" type="text" /></p>
<div class="x"></div>
<p id="captcha-error" class="error">Are you sure about your calculations?</p>
<script type="text/javascript">
generate_captcha('lcaptcha');
</script>
<div class="x"></div>
<input class="submit" name="send_contact" type="submit" value="Send" /><input class="submit" type="reset" value="Reset" />
</form>
</div>
<div id="message_sent" style="display: none;">
<h1>Your message has been sent</h1>
<p>We'll contact you as soon as possible.</p>
<p>You can now <a href="./">go back</a> to home page.</p>
</div>
<!-- end of contact form --></div>
但是电子邮件没有发送出去......我想知道我的php文件中有什么问题导致表单无法触发所述电子邮件......