无法联系表格上班

时间:2017-10-05 15:36:23

标签: php contact-form

我的网站有一个基本的联系表单,但我无法让它工作。表单就像发送一样,但我从未收到表单中的电子邮件。它使用twitter bootstrap。我从freehtml模板获得了初始代码。我将表格上传到www.tonyaespinoza.com/walnut/contact.html作为临时位置,以便将其上传到服务器进行测试。

以下是HTML表单:

<div class="col-md-6">
<form method="post" name="contactForm" role="form" id="contactForm" 
action="sendEmail.php">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" id="message" name="message" cols="30" rows="10" 
class="form-control"></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn btn-special" value="Send Message">
<div class="submitting"></div>
</div>
</form>
<div id="form-message-warning"></div>
<div id="form-message-success">
Your message was sent, thank you!</div>
</div>

这是php:     

$to = 'my_mail@yahoo.com';

function url(){
return sprintf(
"%s://%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['SERVER_NAME']
);
}

if($_POST) {

$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$contact_message = trim(stripslashes($_POST['message']));

if ($subject == '') { $subject = "Contact Form Submission"; }

// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= nl2br($contact_message);
$message .= "<br /> ----- <br /> This email was sent from your site " . 
url() . " contact form. <br />";

// Set From: header
$from =  $name . " <" . $email . ">";

// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

ini_set("sendmail_from", $to); // for windows server
$mail = mail($to, $subject, $message, $headers);

if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }

}

?>

0 个答案:

没有答案