Trying to test send a HTML email to myself using PHP but the PHP code inside the HTML does not work and I don't know why. Sorry if I'm not very clear, I'm quite new to this
<?php
$ccode = rand(1000, 9999);
$to = "[email protected]";
$from = "[email protected]";
$subject = "Confirmation Code";
echo $ccode;
//begin of HTML message
$message = '<html>
<head>
<title> Confirmation Code</title>
</head>
<body style="background-color:#004d4d">
<div style= "text-align:center"> <img src="example.png" alt="Logo" width="300" height="300" align="top;center"> </div>
<h1 style="font-family:verdana; color:white; text-align:center"> This is your confirmation code: </h1>
<p style= "text-align:center;font-size:400%;color:#009999; font-family:arial">
<b>
//code that isn't working
<?php
$ccode = rand(1000, 9999);
echo $ccode;
?>
</b>
</p>
<p style= "text-align:center; font-family:verdana; color:white"> Please enter this code into the application. </p>
</body>
</html>';
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
The email sends as usual but the PHP part inside the email does not work and prints "$ccode" instead.
I would appreciate any kind of help or advice on this thank you!