私はちょうどphpの基礎を学び始め、w3schoolsクラスのコンテンツを理解したいと思っています。jqueryの検証でphpでメールを送る方法
<form role="form" method="POST" id="main-contact-form">
<br style="clear:both">
<h3 style="margin-bottom: 25px; text-align: center;">Contact a Conveyancing Property Lawyer Now</h3>
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="email" name="email" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" required>
</div>
<div class="form-group">
<textarea class="form-control" type="textarea" id="message" placeholder="Message" maxlength="140" rows="7" name="message"></textarea>
<span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
</div>
<button type="submit" id="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
その後、私のjqueryのファイルは、次のようになります:私のHTMLは次のようになります
私が見ることができるものから
$('#main-contact-form').submit(function(event){
event.preventDefault();
$.ajax({
type:'post',
url:'sendememail.php',
data:$(this).serialize(),
success:function(response){
if(response==1)
{
setInterval(function(){$('.review_form').html('<h5><center><div class="alert alert-success">Review Successfully Submitted......</div></center></h5>');},5);
}
else
{
setInterval(function(){$('.review_form').html('<h5><center><div class="alert alert-danger">Sorry Your Review Was Not Submitted......</div></center></h5>');},5);
}
}
});
});
、これは電子メールの送信の方法について、多かれ少なかれです。
01:<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "[email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>
私sendemail.phpは、このようになります
<?php
extract($_POST);
$to = $email;
$subject = $subject;
$txt = $message;
$headers = "[email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>
私は送信ボタンをクリックすると、私はあなたが画像で見ることができますエラーが出る:
はあなたが助けることができると思います。事前
ページを更新せずにフォームからPHPにデータを送信するには、AJAX http://api.jquery.com/jquery.ajax/ –