-4

I am sending password reset link using html email in php. This is structure of my code. First is html email:

<?php $bodymessage= '<table border="0" cellpadding="0" cellspacing="0" width="100%" >;
 $bodoymessaage= .='<a href="$link"' .....?>

then I've setup heaeders

 <?php $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 ?>

and after this i recieve form fields and mail function like this

if($passreset){
       mail($to, $subject, $bodymessage, $headers);
} 

now problem is that I've to get reset link and place it in html template thats being set in query and that comes after html template and headers , my questions is what should be order of template , headers and form query that i may get reset link in html template here $bodoymessaage= .='<a href="$link"' .....?>

1

1 Answer 1

3

When you use ', the variables are not expanded. So kindly use double quotes or, use string concatenation in PHP:

$bodoymessaage= .='<a href="$link"' .....?>
//--------------------------^^^^^ -- This doesn't work.

Change the above code to either:

$bodoymessaage= .="<a href=\"{$link}\"" .....?>         // Use double quotes Or
$bodoymessaage= .='<a href="' . $link . '"' .....?>   // String Concatenation

If you see how PHP Interprets Strings:

$var = "Var";
'$var';    // $var
"$var";    // Var
"{$var}"   // Var
Sign up to request clarification or add additional context in comments.

11 Comments

so will it get value that comes after this in order?
@Sikander The main thing is the quotes buddy. Yes. Check the updated explanation.
let me try this if it helps me ,
@Sikander Yeah, please. If it works, don't forget to mark my answer. :)
I would mention "{$var}" is the best practice to replace variable in string.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.