【问题标题】:Click on button to reply an email in PHP单击按钮以使用 PHP 回复电子邮件
【发布时间】:2014-01-07 17:23:41
【问题描述】:

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

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>

这可以实现吗?我想在 Internet 和 Intranet 上发送应用程序。

【问题讨论】:

  • 给按钮不同的值,然后检查哪个通过了。
  • 好的,所以我应该在邮件之间嵌入 PHP 标签并使用值来实现批准/拒绝,对吗?

标签: javascript php email


【解决方案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'));

【讨论】:

  • 这是正确的,但是,我们将如何通过单击批准来实现回复。单击批准时,邮件应作为回复。这样每个用户都可以申请批准,经理可以相应地批准或拒绝。
  • 将 Javascript 放入 PHP 时出现语法错误,它在 Dreamweaver 中显示。但是,如果我把它放在外面,它就不会传递变量。
  • 我更新了。 $(document).ready(function(){。打开和关闭标签。
猜你喜欢
  • 2023-03-23
  • 2019-05-12
  • 1970-01-01
  • 2014-03-19
  • 2016-05-21
  • 2013-06-23
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多