我想使用jQuery和PHP發送電子郵件,但不知何故,即使PHP成功執行,我也沒有收到電子郵件。爲什麼PHP表單不發送電子郵件
這是我的javascript代碼:
<script type='text/javascript'>
$("#formoid").submit(function(event) {
event.preventDefault();
var $form = $(this),
url = $form.attr('action');
var posting = $.post(url, {
name: $('#name').val(),
email: $('#email').val(),
message: $('#message').val()
});
posting.done(function(data) {
$("#result").empty().append('Thank you for contacting. Will get back to you as sson as possible.');
});
});
</script>
我的PHP是這樣的:
<?php
if(isset($_POST['submit'])){
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Portfolio form submission";
$message = $name . " " . $email . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
}
?>
當我提交表單,並檢查DOM中,我看到的結果是好的。 在XHR細節,它表明:
statusText: "OK"
難道我做錯了嗎?
編輯: 的要求添加HTML:
<form class="no-bottom" id="formoid" action="contact.php" title="" method="post">
<label for="name" class="sr-only">Name</label>
<input type="text" class="underline" name="name" id="name" placeholder="Your name..." required>
<label for="email" class="sr-only">Email</label>
<input type="email" class="underline" name="email" id="email" placeholder="Your email..." required>
<label for="message" class="sr-only">Message</label>
<textarea class="underline" name="message" id="message" cols="30" rows="6" placeholder="Here goes the message..." required></textarea>
<div class="margin-1"></div>
<input type="submit" value="Send it">
</form>
檢查'isset($ _ POST [ '提交'])'當它不從客戶 – Tushar
哪裏發送你執行這個PHP代碼?你是否安裝並配置了MailServer? –
在這裏提供你的'html'。 –