How to include an HTML template to send by PHP mail?

1

I need to pass the variable with a template to send and organize the code.

define(FULLNAME, $fullname);
define(EMAIL, $email);

$body = include('../templete/welcome.php?name='.FULLNAME);

$header = "From: Team app <[email protected]> \r\n";
$header .= "Bcc: [email protected] \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/html";

return $body;
mail(EMAIL, "¡Welcome to Dolphy!", $body, $header);
    
asked by Luis Laguna 22.10.2016 в 04:23
source

2 answers

1

I think you're making the call to the template wrong. Try this way:

define(FULLNAME, $fullname);
define(EMAIL, $email);

$body = file_get_contents('../templete/welcome.php');

$body = str_replace("nombrexxx", FULLNAME, $body);

$header = "From: Team app <[email protected]> \r\n";
$header .= "Bcc: [email protected] \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/html";

return $body;
mail(EMAIL, "¡Welcome to Dolphy!", $body, $header);

You just have to change your file welcome.php , so that where you have the variable that you pass, put nombrexxx . In this way, with the instruction str_replace you will change the value you spend

    
answered by 22.10.2016 в 13:37
0

I got it this way

function send_ResetPass($fullname, $email, $pass){
$newpassmd5 = md5($pass);

$path = '../templete/pass.html';
if(file_exists($path)){
    $tpl = file_get_contents($path);
}
$body = str_replace('{{content}}', strtoupper($fullname), $tpl);
$body = str_replace('{{pass}}', $pass, $body);

$header = "From: El equipo Dolphy <[email protected]> \r\n";
$header .= "Bcc: [email protected] \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/html";

if (mail($email, "Alguien solicitó una nueva contraseña para tu cuenta de Dolphy", $body, $header)) {
    mysql_query("UPDATE pw_user SET password ='$newpassmd5' WHERE user = '$email'");
}

}

    
answered by 28.02.2017 в 04:40