我在使用此电子邮件表单时遇到问题。没有 php 错误代码或任何东西,电子邮件永远不会送达...整个代码示例是包含在我网站的多个页面上的文件。表单提交到它所在的任何页面,并且可以工作,除了我不知道为什么它不会发送电子邮件的事实。它似乎没有处理包含发送电子邮件代码的 else 语句。
<div class="green_box" id="contact_us">
<h3>CONTACT US</h3>
<div class="white_box">
<?php
if ($_POST['submitted']==1) {
$errormsg = ""; //Initialize errors
if ($_POST[your_name]){
$your_name = $_POST[your_name];
}
else {
$errormsg = "You did not enter your Name";
}
if ($_POST[your_email]){
$your_email = $_POST[your_email];
}
else {
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " or your Email";
}else{
$errormsg = "You did not enter your Email";
}
}
if ($_POST[your_message]){
$your_message = $_POST[your_message];
}
else {
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " or your Message";
}else{
$errormsg = "You did not enter your Message";
}
}
if (strlen($errormsg) > 1) {
echo "<p><strong>" . $errormsg . ".</strong><br>Please try again.</p>";
}
else {
$email_to = "willyfresh@gmail.com"; // recipient inbox
$email_subject = "Fore A Partners Website Contact Form";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($your_name)."\n";
$email_message .= "Email: ".clean_string($your_email)."\n";
$email_message .= "Comments: ".clean_string($your_message)."\n";
$headers = 'From: '.$your_email."\r\n".
'Reply-To: '.$your_email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
echo "<p>Thank you for contacting us. We will be in touch with you very soon.</p>";
}
}
?>
<form name="contactform" method="post">
<p>Name<br><input type="text" name="your_name" maxlength="80" size="45"></p>
<p>Email<br><input type="text" name="your_email" maxlength="80" size="45"></p>
<p>Message<br><textarea name="your_message" maxlength="1000" rows="6" cols="30"></textarea></p>
<input type="hidden" name="submitted" value="1">
<p><input type="image" src="../btn_submit.png" alt="Submit" name="submit"></p>
</form>
</div>
</div>