I have a problem . I have a form that I need to send through email to a godaddy outlook mail account. The problem is that the form submits sometimes and some other times it doesn't . here is the code for the js where ajax call is made , the html where the button is (I made it as a p with #SendPlan as id) and the php where the email is sent (I also used phpmailer): ($Type is always correct so it always goes inside the ajax, all other variables are assumed to have values already too)
$(document).ready(function () {
$("#SendPlan").click(function () {
if($Type=="Cake Customization")
{ $.ajax({
url: "plan_mail.php",
data: {
'Type' : $Type,
'CakeEvent': $CakeEvent,
'CakeSize': $CakeSize,
'Date' : $Date,
'Name' : $Name,
'Location' : $Location,
'Email' : $Email,
'Phone' : $Phone,
'Notes' : $Notes,
},
cache: "false",
type: "POST",
success: function(response) {
document.getElementById('mailStatus').innerHTML="<h2 class=\"planthankyou\">Thank You For Your Submission. We Will Contact You Soon!</h2>";
},
error: function (response){
alert(response);
$('#dialog-form').dialog('close');}
});
}
});
});
and this is the plan_mail.php that ajax is calling:
$Type= $_POST['Type'];
if($Type=="Cake Customization")
{
$Occasion= $_POST['Occasion'] ;
$CakeEvent = $_POST['CakeEvent'];
$CakeSize= $_POST['CakeSize'];
$Date= $_POST['Date'] ;
$Name= $_POST['Name'] ;
$Location= $_POST['Location'] ;
$Email= $_POST['Email'] ;
$Phone= $_POST['Phone'] ;
$Notes= $_POST['Notes'] ;
$message = "
Date : " . $Date ."
Name : " . $Name . "
Location : " . $Location . "
Email : " . $Email
. "
Phone : " . $Phone ."
Notes : " . $Notes
."
Type : " . $Type . "
Cake Event : " . $CakeEvent . "
Cake Size : " . $CakeSize;
}
require("/home/specialeventsleb/public_html/phpmailer/PHPMailer/class.phpmailer.php");
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'anemail';
$mail->Password = 'apassword';
$mail->SetFrom('anemail', 'FromEmail');
$mail->addAddress('anemail', 'ToEmail');
$mail->Subject = 'Message from Special Events Website';
$mail->Body = $message;
$mail->send();
and finally this is part of the html used where the #SendPlan is:
<div id="Plan">
<div id="SubPlan">
<!--Shared Final Section-->
<div id="FinalStep">
<div >
<div class="PlanWrapper" id= "mailStatus" >
<div class="row"><div class="col-xtra-12"><h1>CUSTOMIZE YOUR DISPLAY TABLE</h1></div></div>
<div class="row"><div class="col-xtra-12" ><p>FINAL STEP</p></div></div>
<div class="row">
<div class="col-sm-6 col-sm-6">
<input name="DecorationOther" placeholder="WHAT IS THE DATE?" class="Date" />
<input name="DecorationOther" placeholder="NAME" class="Name"/>
<input name="DecorationOther" placeholder="LOCATION" class="Location"/>
<input name="DecorationOther" placeholder="E-MAIL" class="Email"/>
<input name="DecorationOther" placeholder="TELEPHONE" class="Phone"/> </div>
<div class="col-sm-6 col-sm-6"> <textarea name="DecorationOther" placeholder="NOTES AND MESSAGES" class="Notes"></textarea> </div>
</div>
<div class="row"><div class="col-xtra-12" style="text-align:right"><p id="SendPlan">SEND</p></div></div>
</div>
</div>
</div>
</div>
</div>