我想通过 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/