Send email with a template using php

后端 未结 9 2174
南旧
南旧 2020-12-04 07:45

How can I send an email using php then add a template design in the email? I\'m using this:

$to = \"someone@example.com\";  
$subject = \"Test mail\";  
$mes         


        
9条回答
  •  爱一瞬间的悲伤
    2020-12-04 08:28

    Why not try something as simple as this :

    $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;
    

    Your template file being something like :

    
    
    

    My name is {{ name }} and I am {{ age }} !

提交回复
热议问题