我正在爲客戶端登臺,我試圖從頭開始創建窗體而不是使用插件。窗體不發送
我不確定我要去哪裏錯。該頁面不斷刷新到主頁,並且不發送電子郵件。在我的代碼
可能有人請指出哪裏我已經錯了...
提前感謝!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Test';
$to = '[email protected]';
$subject = 'Hello';
if ($name == "" OR $email == "") {
echo "You must specify a value for name, email address, and message.";
exit;
}
foreach($_POST as $value){
if(stripos($value,'Content-Type:') !== FALSE){
echo "There was a problem with the information you entered.";
exit;
}
}
require_once("assets/inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)){
echo "You must specify a valid email address.";
}
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
header("Location: http://natashamcdiarmid.com/clients/JLP/wp/contact/?status=thanks");
exit;
}
?>
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
<p>Thanks, I'll get back to your shortly!</p>
<?php } else ?>
<form method="post" action="contact">
<p><label>Name</label></p>
<input name="name" placeholder="Type Here">
<p><label>Email</label></p>
<input name="email" type="email" placeholder="Type Here">
<p><label>Message</label></p>
<textarea name="message" placeholder="Type Here"></textarea>
<p><label>*What is 2+2?</label></p>
<input name="human" placeholder="Type Here">
<p><input id="submit" name="submit" type="submit" value="Submit"></p>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
</form>
如果事情不能按預期工作:瀏覽器中的開發控制檯會說什麼?這就是你應該看到一個錯誤,解釋什麼是問題... – arkascha
對不起,我是一個新手。我使用開發人員控制檯來編輯css,但從不查看問題。你能否擴大? – tmcd