1$variables = array();
2
3$variables['name'] = "Robert";
4$variables['age'] = "30";
5
6$template = file_get_contents("template.html");
7
8foreach($variables as $key => $value)
9{
10 $template = str_replace('{{ '.$key.' }}', $value, $template);
11}
12
13echo $template;
14
1<?php
2$to = 'user@example.com';
3$subject = "Send HTML Email Using PHP";
4
5$htmlContent = '
6<html>
7<body>
8 <h1>Send HTML Email Using PHP</h1>
9 <p>This is a HTMl email using PHP by CodexWorld</p>
10</body>
11</html>';
12
13// Set content-type header for sending HTML email
14$headers = "MIME-Version: 1.0" . "\r\n";
15$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
16
17// Additional headers
18$headers .= 'From: CodexWorld<info@codexworld.com>' . "\r\n";
19$headers .= 'Cc: welcome@example.com' . "\r\n";
20$headers .= 'Bcc: welcome2@example.com' . "\r\n";
21
22// Send email
23if(mail($to,$subject,$htmlContent,$headers)):
24 $successMsg = 'Email has sent successfully.';
25else:
26 $errorMsg = 'Email sending fail.';
27endif;
28?>
29