“接受”和“拒绝”按钮在邮件中不起作用

时间:2016-06-09 06:18:45

标签: php

我发送邮件后,用户提交表单批准通过邮件链接拒绝数据。这是代码:

$subject = 'User needs approval';
$message = 'The user $empname needs your approval' .
'----------------------------------- ' . "\r\n" .
'Accept: ' . $accept_link . "\r\n" .
'Decline: ' . $decline_link . "\r\n";

$_headers = 'From:admin@yourwebsite.com' . "\r\n"; // Set FROM headers
//mail($supemail, $subject, $message, $headers); // Send the email
fnMail($supemail,"mailb@mail.com"," Web master","reimbursement Form",$message);

接受和拒绝的链接是:

$accept_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e=" . $empemail . "&h=" . hash('sha512', 'ACCEPT');

$decline_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e="  . $empemail . "&h=" . hash('sha512', 'DECLINE');

这里是approval.php文件:

$hash = $_GET['h'];
$email = $_GET['e'];
if($hash == hash('sha512', 'ACCEPT')){
$res=execQuery('oth','update form set approved=1 where empemail="$email"');

if(count($res)>0){
   fnMail($email,"mk.web@mattsenkumar.com","MattsenKumar Web master","Contact Front registration",'APPROVED');
}
}else if($hash == hash('sha512', 'DECLINE')){

fnMail($email,"mk.web@mattsenkumar.com","MattsenKumar Web master","Contact Front registration",'DECLINE');
}

但是我收到了这样的邮件:

The user $empname needs your approval----------------------------------- Accept: Decline: 

2 个答案:

答案 0 :(得分:1)

这是第1天的基本PHP语法:变量不会插入到单引号字符串中。 Read the docs,执行此操作:

$message = "The user $empname needs your approval" .

要使消息中包含接受和拒绝链接,您必须在使用它们之前定义它们,如下所示:

$accept_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e=" . $empemail . "&h=" . hash('sha512', 'ACCEPT');
$decline_link = "http://communique/elegant-contact-form/quick-contact/ajax/approval.php?e="  . $empemail . "&h=" . hash('sha512', 'DECLINE');
$message = "The user $empname needs your approval" .
'----------------------------------- ' . "\r\n" .
'Accept: ' . $accept_link . "\r\n" .
'Decline: ' . $decline_link . "\r\n";

答案 1 :(得分:-2)

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

尝试设置标题

或检查以下stackoverflow链接

希望这会有所帮助

link