gpt4 book ai didi

javascript - 单击按钮以 PHP 方式回复电子邮件

转载 作者:行者123 更新时间:2023-11-28 01:40:34 24 4
gpt4 key购买 nike

我有一个表格。当用户填写并提交时。它将向部门主管发送一封带有表格附件的邮件。该电子邮件有两个按钮“批准”和“拒绝”。现在,当经理“批准”时,它应该回复批准消息和附件。但是,当他单击“拒绝”时,应回复消息“已拒绝”。以下是我现在拥有的。

PHP 将应用程序发送给经理。我正在使用 PHP 邮件程序PHP

  $body = file_get_contents('Source/auth.php'); // Authentication Page
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; // or 465
$mail->IsHTML(true);
$mail->Username = $_SESSION['member_name'];
$mail->Password = $_SESSION['member_password'];
$mail->SetFrom($_SESSION['member_name']);
$mail->Subject = "Application";
$mail->Body = $body;
$mail->AddAddress($memail);// Manager of the Department from DB
$mail->AddReplyTo($memEmail, "name"); // Reply mail
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/Application/PDF/'.$file.'.pdf');
$mail->Send(header ('Location: login_succ.php'));

我创建了一个小型身份验证页面“auth.php”;包含在发件人的邮件中。HTML

<form name="form1" method="GET" action="" onSubmit="return verify()">
<div>
<button>Approved</button> // Reply with approval form as attachment
<button>Rejected</button> // Reply 'Rejected'
</div>
</form>

这可以实现吗?我想通过互联网和内联网发送申请。

最佳答案

有些人喜欢这样:

<form name="form1" method="GET" action="" onSubmit="return verify()">
<div>
<button class="bt" action="aprove">Approved</button> // Reply with approval form as attachment
<button class="bt" action="reject">Rejected</button> // Reply 'Rejected'
</div>
</form>

<script type="text/javascript">

$(document).ready(function() {
$(".bt").click(function(event) {

var action = $(this).attr("action");

$.ajax({
url: '/path/to/fileEmail.php',
type: 'POST',
dataType: 'json',
data: {action: 'action'},
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
});

});
});

</script>

<?php
//File fileEmail.php
$action = $_POST["action"];

if($action == "aprove"){
$message = "Some msg to aprove";
$attachment = $_SERVER['DOCUMENT_ROOT'].'/Application/PDF/aprove.pdf';
}else if($action == "reject"){
$message = "Some msg to reject";
$attachment = $_SERVER['DOCUMENT_ROOT'].'/Application/PDF/reprove.pdf';
}

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; // or 465
$mail->IsHTML(true);
$mail->Username = $_SESSION['member_name'];
$mail->Password = $_SESSION['member_password'];
$mail->SetFrom($_SESSION['member_name']);
$mail->Subject = "Application";
$mail->Body = $message;
$mail->AddAddress($memail);// Manager of the Department from DB
$mail->AddReplyTo($memEmail, "name"); // Reply mail
$mail->AddAttachment($attachment);
$mail->Send(header ('Location: login_succ.php'));

第二种情况:

将内容写入电子邮件:

<a href="http://www.yoururl.com/fileEmail.php?action=aprove"></a>
<a href="http://www.yoururl.com/fileEmail.php?action=reject"></a>

服务器中 fileEmail.php 的内容:

<?php
//File in your server: http://www.yoururl.com/fileEmail.php
$action = $_GET["action"];

//Create a authentication for your user
$auth = someMethodToAuth(); //If ok, register the sessions to send email
if(!$auth){
die("You dont have permission to access this page!");
}

if($action == "aprove"){
$message = "Some msg to aprove";
$attachment = $_SERVER['DOCUMENT_ROOT'].'/Application/PDF/aprove.pdf';
}else if($action == "reject"){
$message = "Some msg to reject";
$attachment = $_SERVER['DOCUMENT_ROOT'].'/Application/PDF/reprove.pdf';
}

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; // or 465
$mail->IsHTML(true);
$mail->Username = $_SESSION['member_name'];
$mail->Password = $_SESSION['member_password'];
$mail->SetFrom($_SESSION['member_name']);
$mail->Subject = "Application";
$mail->Body = $message;
$mail->AddAddress($memail);// Manager of the Department from DB
$mail->AddReplyTo($memEmail, "name"); // Reply mail
$mail->AddAttachment($attachment);
$mail->Send(header ('Location: login_succ.php'));

关于javascript - 单击按钮以 PHP 方式回复电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20977954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com