Home > Back-end >  How to show a php variable inside html tags?
How to show a php variable inside html tags?

Time:01-11

I'm using phpmailer to send otp via email, in the Body part of the email, I'm trying to show a php variable $otp inside $otp tag but it just Shows $otp instead of the value

//value of $otp
$ot=rand(100000,999999);
$otp=strval($ot);

of the variable. I tried with the below code.

    $mail->Body    = 
    '<h2 style="background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;">$otp</h2>
    ';

but this only returns $otp in mail and not it's value

CodePudding user response:

If you whant to display a php variable in your string you need to close the string with ' and then use a . after the dot you can write php.

In your case you use the single quote so it will look like 'string' . $variable. 'string';

$mail->Body = '<h2 style="background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;">'
    . $otp . '</h2>';
  • Related