dongyixiu3110 2017-12-19 16:31
浏览 73

Ajax表单并不总是发送到电子邮件

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)