我有一张表格。当用户填写并提交时。它将通过表格的附件向部门负责人发送邮件。这封电子邮件有两个按钮'Approve'& '拒绝'。现在当经理'批准'时,它应该回复批准消息和附件。但是,当他点击“拒绝”时,应回复“拒绝”消息。以下就是我现在所拥有的。
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>
这可以实现吗?我想在互联网和内联网上发送申请。
答案 0 :(得分:1)
有人喜欢这样:
<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'));