亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我怎樣才能從 phpmailer 中的輸入中給出主題和正文消息

我怎樣才能從 phpmailer 中的輸入中給出主題和正文消息

PHP
慕田峪4524236 2023-08-11 16:41:29
這是index.php 現在我所能做的就是給 $mail->Subject 和 $mail->body 賦值,但我希望它是動態的,例如在這里我想為主題和消息提供 2 個輸入并傳遞它在 $mail->Subject 和 $mail->Body 上,因為 post 方法是在 ajax 上,我無法將兩個值從輸入字段傳遞到 send_mail.php 任何幫助將不勝感激<?php    //index.php        $connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");    $query = "SELECT * FROM customer ORDER BY customer_id";    $statement = $connect->prepare($query);    $statement->execute();    $result = $statement->fetchAll();        ?>    <!DOCTYPE html>    <html>    <head>               <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>    </head>    <body>    <br />    <div class="container">              <br />        <div class="table-responsive">                <table class="table table-bordered table-striped">                <tr>                    <th>Customer Name</th>                    <th>Email</th>                    <th>Select</th>                    <th>Action</th>                </tr>
查看完整描述

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"];

希望它能回答您的問題。


查看完整回答
反對 回復 2023-08-11
?
偶然的你

TA貢獻1841條經驗 獲得超3個贊

首先:使用ajax僅發送用戶id(最好在js中使用fetch()來請求),然后從數據庫中獲取文件(send_mail.php)中的用戶數據(用戶驗證)!

如果不是通過會話,則需要通過檢查數據庫來進行用戶驗證。

查看完整回答
反對 回復 2023-08-11
  • 2 回答
  • 0 關注
  • 127 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號