-1

I am sending a mail after user submits form to approve are disapprove the data through link in mail. Here is the code:

$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);

The link to accept and decline is:

$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');

and here is the approval.php file:

$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');
}

But I got the mail like this:

The user $empname needs your approval----------------------------------- Accept: Decline: 
halfer
  • 19,824
  • 17
  • 99
  • 186
  • This looks like it should work OK. Can you provide the actual code that includes the definition of `$accept_link` as well as `$message`? `$empname` is not being interpreted because it is inside single quotes, you should replace `'` with `"` or use `'The user ' . $empname . ' needs your approval'`. To ensure the user followed the link you sent them your hash should include their email address and a known secret. If you're just hashing `ACCEPT` and `DECLINE` you might as well just write `ACCEPT` and `DECLINE`. You are defining `$_headers` but not using it anywhere. Where is `fnMail()` defined? – Matt Raines Jun 09 '16 at 06:55
  • To make it work use html in your mail, it will help you to trigger the link. Use Anchor link, rather using row text – JiteshNK Jun 09 '16 at 07:03
  • **JiteshNK** can you help me with that – Danish Baksh Jun 09 '16 at 07:05
  • Something like this `$message = "
    The user $empname needs your approval
    "; $messsge .= "";`
    – JiteshNK Jun 09 '16 at 07:31

2 Answers2

1

This is day-1 basic PHP syntax: variables are not interpolated into single-quoted strings. Read the docs, do this:

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

For the accept and deny links to be included in the message you must define them before you use them, like this:

$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";
Synchro
  • 35,538
  • 15
  • 81
  • 104
  • thanks for the $empname but i am asking about $accept_link and decline link i receive the mail like this **The user $empname needs your approval----------------------------------- Accept: Decline:** but here accept and decline is not clickable means there is no link with them. – Danish Baksh Jun 09 '16 at 06:58
  • I am receiving mail **fnMail()** is working fine its defined in mailfunction.php file – Danish Baksh Jun 09 '16 at 07:04
  • It's hard to tell from your question, but it looks like you define the link variables *after* you build the body string, so it will not contain them. – Synchro Jun 09 '16 at 07:05
  • thanks bro i have edited approval.php file to something like this :- `if($hash == hash('sha512', 'ACCEPT')){ $qry="update form set approved='1' where empemail='$email';"; $res=execQuery("oth",$qry); if(count($res)>0) { echo 'Approved'; fnMail($email,"mk.web@mattsenkumar.com","MattsenKumar Web master","Contact Front registration",'APPROVED'); }` **and its works perfectly** again thanks for your help – Danish Baksh Jun 09 '16 at 07:57
  • Make sure you sanitise/escape `$email` to avoid SQL injection. – Synchro Jun 09 '16 at 08:05
-2
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

Try setting the headers

or check this below stackoverflow link

hope this will help

PHP mail() - How to put an html link in an email?

Community
  • 1
  • 1