php - 单击按钮时触发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);
}
?>
解决方案
推荐阅读
- r - 我试图创建一个三向交互图,但我的 x 轴标签搞砸了
- javascript - 渲染组件数组时,单击按钮时总是会拾取数组的最新元素
- django - 即使将属性名称用双引号括起来,也会出现 JSON 解码错误
- python - 如何修复 vscode 中的 import xxx 错误?
- passenger - 如何将参数传递给PassengerStartupFile?
- powerbi - 我可以用 Dataset 组织历史吗?
- python - 来自 ThreadPoolExecutor 的 concurrent.futures.Future 有时会挂起
- flutter - 从另一个文件回到 main.dart 中的类
- python - str 包含来自列表并通过列表项区分
- javascript - 在js条件下加载脚本的最佳方法是什么