首页 > 解决方案 > 单击按钮时触发php的邮件功能

问题描述

我想触发单击按钮时的mail()功能。php

我试过使用;

 <button id="Next" type="button" onclick="executeShellScript();" >Next</button>

对于button. 请注意,按钮的类型必须始终是您不能submit用于我的情况的按钮。

在javascript方面

<script type="text/javascript">

        function executeShellScript(){
           <?php mail(); ?>
        }
    </script>

对于 php

      <?php
            use PHPMailer\PHPMailer\PHPMailer;
            use PHPMailer\PHPMailer\Exception;
            global $value;
            $value="100";
         function mail(){
            require 'PHPMailer/src/Exception.php';
            require 'PHPMailer/src/PHPMailer.php';
            require 'PHPMailer/src/SMTP.php';
            global $message;
            global $toAddress;
            $toAddress = "xxxx@gmail.com"; //To whom you are sending the mail.
            $messages  = <<<EOT
                <html>
                   <body>
                     Your value is
                     <br>
                     <h1 align="center">
                   </body>
                </html>
            EOT;
            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->SMTPAuth    = true;
            $mail->Host        = "mail.xxx.com";
            $mail->Port        = 587;
            $mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true
                )
            );
            $message = $messages.$value.'</h1>';
            $mail->IsHTML(true);
            $mail->Username = "xxx@xxx.com"; // your gmail address
            $mail->Password = "xxxxxxx"; // password
            $mail->SetFrom("xxxxx@xxxx.com");
            $mail->Subject = "Try "; // Mail subject
            $mail->Body    = $message;
            $mail->Address($toAddress);
          }
        ?>

标签: php

解决方案


推荐阅读