我已經看過各種解決方案,但我無法讓我的聯繫表單工作。 **問題是電子郵件實際上不會發送給我,一切都可以在客戶端運行,但是我沒有收到郵件。所以我來這裏肯定會得到重複的問題標籤。這裏是我的代碼:讓我的AJAX/PHP聯繫表格發送電子郵件
<form method="post" class="reply" id="contact" action="process.php">
<fieldset>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<label>Name: <span>*</span></label>
<input class="form-control" id="name" name="name" type="text" value="" required>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<label>Email: <span>*</span></label>
<input class="form-control" type="email" id="email" name="email" value="" required>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<label>Subject: <span>*</span></label>
<input class="form-control" id="subject" name="subject" type="text" value="" required>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<label>Message: <span>*</span></label>
<textarea class="form-control" id="text" name="text" rows="3" cols="40" required></textarea>
</div>
</div>
</fieldset>
<button class="btn btn-normal btn-color submit bottom-pad" type="submit">Send</button>
<div class="success alert-success alert" style="display:none">Your message has been sent successfully.</div>
<div class="error alert-error alert" style="display:none">E-mail must be valid and message must be longer than 100 characters.</div>
<div class="clearfix">
</div>
</form>
這裏是我的process.php
<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if (isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['text']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
// detect & prevent header injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ($_POST as $key => $val) {
if (preg_match($test, $val)) {
exit;
}
}
// PREPARE THE BODY OF THE MESSAGE
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . htmlentities($_POST['text']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
// CHANGE THE BELOW VARIABLES TO YOUR NEEDS
$to = '[email protected]';
$subject = $_POST['subject'];
$headers = "From: " . $_POST['email'] . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
}
?>
我完全新的形式,所以在此先感謝您的幫助。如果有任何資源,你可以建議這將是偉大的。謝謝!
到底在哪這裏會失敗?表單是否發佈到服務器?服務器端的值是否你期望它們是? PHP代碼是否按預期執行?郵件是否已發送,而您只是沒有在收件箱中看到它?你需要縮小問題的範圍。 – David