douxiaochun4964 2012-12-18 22:27
浏览 61
已采纳

PHP邮件脚本在使用jQuery时不发送电子邮件.ajax()

I'm completely stumped on this. I'm trying to use jQuery ajax function to send POST data to an email script.

Here is the jQuery code.

$('#bas-submit-button').click(function () {
    var baslogo = $('input#bas-uploaded-logo').val();
    var basscent = $('input[name="scent"]:checked').val();
    var bascolor = $('input[name="color"]:checked').val();
    var basdistributor = $('select#bas-distributor-name').val();
    var basname = $('input#bas-contact-name').val();
    var basemail = $('input#bas-contact-email').val();
    var bascontactphone = $('input#bas-contact-phone').val();
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var baspantone = $('input#pantone').val();
    var basclip = $('input[name="clip-name"]:checked').val();
    var dataString = 'bas-contact-name=' + basname + '&bas-contact-email=' + basemail + '&bas-contact-phone=' + bascontactphone + '&bas-uploaded-logo=' + baslogo + '&scent=' + basscent + '$color=' + bascolor + '&clip-name=' + basclip + '&pantone=' + baspantone + '&bas-distributor-name=' + basdistributor;
    $.ajax({
        type: "POST",
        url: "build-a-smen-submit.php",
        data: dataString,
        success: function () {
            $("#bas-submit-message").removeClass("error").addClass("success").html("Virtual Sample Submitted!").fadeIn(200).delay(5000).fadeOut(200);
        }
    });
    return false;
});

And my PHP script.

<?

/* config start */
$emailAddress = '*****';
$ccAddress = '*****';
/* config end */

require "class.phpmailer.php";

session_start();

if($_POST['bas-submit-button']=='Submit'){

$msg='Name: '.$_POST['bas-contact-name'].'<br />
Email: '.$_POST['bas-contact-email'].'<br />
Phone: '.$_POST['bas-contact-phone'].'<br /><br />
Options<br /><br />
Logo File: '.$_POST['bas-uploaded-logo'].'<br />
Scent Selection: '.$_POST['scent'].'<br />
Accent Color: '.$_POST['color'].'<br />
Name on clip: '.$_POST['clip-name'].'<br />
Pantone Colors: '.$_POST['pantone'].'<br />
Distributor: '.$_POST['bas-distributor-name'].'<br /><br />
Submitting IP:  '.$_SERVER['REMOTE_ADDR'];

$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($_POST['bas-contact-email'], $_POST['bas-contact-name']);
$mail->AddAddress($emailAddress);
$mail->AddCC($ccAddress);
$mail->SetFrom($_POST['bas-contact-email'], $_POST['bas-contact-name']);
$mail->Subject = 'Build-A-Smen Promotional Product Interest';
$mail->MsgHTML($msg);
$mail->Send();

if($_POST['ajax']){
    echo '1';
}
else{
    if($_SERVER['HTTP_REFERER'])
        header('Location: '.$_SERVER['HTTP_REFERER']);
    exit;
}

};

?>

I believe that the problem lies somewhere in the sending of the POST data from jQuery. If I comment out my jQuery code the php script works fine, but when I run it with the jQuery ajax function I get the ajax success function firing but no email.

  • 写回答

1条回答 默认 最新

  • dougangxin5695 2012-12-18 22:39
    关注

    Your problem is the data: dataString.

    Either serialize like previously stated or try something similair to this:

    data : { basscent : basscent, bascolor : bascolor, } etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程