php email template code example

Example 1: create email template php

$variables = array();

$variables['name'] = "Robert";
$variables['age'] = "30";

$template = file_get_contents("template.html");

foreach($variables as $key => $value)
{
    $template = str_replace('{{ '.$key.' }}', $value, $template);
}

echo $template;

Example 2: cpanel email to email send with php

<? 

$to      = '[email protected]'; 

$subject = 'The test for php mail function'; 

$message = 'Hello'; 

$headers = 'From: [email protected]' . "\r\n" . 

    'Reply-To: [email protected]' . "\r\n" . 

    'X-Mailer: PHP/' . phpversion(); 

mail($to, $subject, $message, $headers); 

?>

Tags:

Php Example