2 回答

TA貢獻1752條經驗 獲得超4個贊
我假設您想為每封電子郵件數據的主題和消息添加兩個輸入。
您可以添加 2 個字段,并在 ajax 中將其與電子郵件數據一起設置并將其傳遞給 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';
有了這個
$mail->Subject = $row["subject"];
$mail->Body = $row["message"];
希望它能回答您的問題。

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