2 回答

TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
我假設(shè)您想為每封電子郵件數(shù)據(jù)的主題和消息添加兩個(gè)輸入。
您可以添加 2 個(gè)字段,并在 ajax 中將其與電子郵件數(shù)據(jù)一起設(shè)置并將其傳遞給 send_mail.php。
JS代碼
<script>
$(document).ready(function(){
$('.email_button').click(function(){
$(this).attr('disabled', 'disabled');
var id = $(this).attr("id");
var action = $(this).data("action");
var email_data = [];
if(action == 'single')
{
email_data.push({
email: $(this).data("email"),
name: $(this).data("name"),
subject: $(this).data("subject"), //or can be grab from input
message: $(this).data("message")
});
}
else
{
$('.single_select').each(function(){
if($(this).prop("checked") == true)
{
email_data.push({
email: $(this).data("email"),
name: $(this).data('name'),
subject: $(this).data("subject"), //or can be grab from input
message: $(this).data("message")
});
}
});
}
$.ajax({
url:"send_mail.php",
method:"POST",
data:{email_data:email_data},
beforeSend:function(){
$('#'+id).html('Sending...');
$('#'+id).addClass('btn-danger');
},
success:function(data){
if(data == 'ok')
{
$('#'+id).text('Success');
$('#'+id).removeClass('btn-danger');
$('#'+id).removeClass('btn-info');
$('#'+id).addClass('btn-success');
}
else
{
$('#'+id).text(data);
}
$('#'+id).attr('disabled', false);
}
})
});
});
</script>
在 send_mail.php 中替換以下行
$mail->Subject = 'i want input to be passed here';
//An HTML or plain text message body
$mail->Body = 'and the body message to be passed here';
有了這個(gè)
$mail->Subject = $row["subject"];
$mail->Body = $row["message"];
希望它能回答您的問題。

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊
首先:使用ajax僅發(fā)送用戶id(最好在js中使用fetch()來請求),然后從數(shù)據(jù)庫中獲取文件(send_mail.php)中的用戶數(shù)據(jù)(用戶驗(yàn)證)!
如果不是通過會(huì)話,則需要通過檢查數(shù)據(jù)庫來進(jìn)行用戶驗(yàn)證。
- 2 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報(bào)