javascript - 在由 javascript 触发的电子邮件中发送一些 php 变量

标签 javascript php html email

我想通过 javascript 的触发器发送一些 php 变量。变量、数据库和脚本可以正常工作,但我无法理解我们的 PHP 部分。

这就是我认为 PHP 应该的样子,但它显然是错误的。我只想发送几个变量。

if{
    $mail = new PHPMailer;
    $mail->isSMTP();
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->CharSet = 'UTF-8';
    $mail->SMTPDebug = 0;
    $mail->Debugoutput = 'html';
    $mail->Host = "host";
    $mail->SMTPAuth = false;
    $mail->Port = 25;
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    $mail->setFrom('noreply', 'hint');
    $mail->addAddress('email.test.com');

    $mail->Subject = 'hint';
    $msg='Allikas: '.$_POST['source']
    $mail->msgHTML('<strong>Hint.</strong>;
    if (!$mail->send()) {
        echo 'ERROR';
        //return false;
        //echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "SUCCESS";
    }
}else{echo "SUCCESS";}

这是我的 javascript 触发器

        else if (checked === true) {
        console.log("asddd")
        "send the stuff (part i need help with")
    }
}

最佳答案

你需要做一个ajax请求

var values = {"source":"the source...", "location":"the location..."}; // add your others variable here...
$.ajax({
        url: "yourphpfile.php",
        type: "post",
        data: values ,
        success: function (response) {
           // it will return the result (SUCCESS or ERROR)  

        },
        error: function(jqXHR, textStatus, errorThrown) {
           console.log(textStatus, errorThrown);
        }
    });

关于javascript - 在由 javascript 触发的电子邮件中发送一些 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50217397/

相关文章:

Javascript日期从20/11/2010到2010年11月20日?

php - 为什么 MySQL 连接被阻塞很多连接错误?

html - 验证解析错误

jquery-plugins - 特定 DIV 的 block UI Jquery 插件

javascript - 使用 jQuery 将类添加到第 n 个属性

javascript - 如何从 api url 的(此)点击事件中提取类名

javascript - 视口(viewport)高度差中断滚动事件

php - 使用 PHP 将 MySQL 数据保存到 Excel 工作表

php - onbeforeunload 事件上的 jQuery.ajax 不起作用

html - 被粘性页脚难住了 - 不会在预期的地方停止