PHPMailer with html template

mail_tempalte.html

<html>
    <body>
        <h1>Account Details</h1>
        <p>Thank you for registering on our site, your account details are as follows:

        Username: %username%

        Password: %password% </p>
    </body>
</html>

sentmail.php

<?php

require 'class.phpmailer.php';

$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP(true);
$mail->CharSet = "utf-8";
// Gmail
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "goocoder@gmail.com"; // GMAIL username
$mail->Password = "GoocoderPassword"; // GMAIL password

$mail->From = 'goocoder@gmail.com';
$mail->FromName   = 'Goocoder';
$email_template = 'mail_tempalte.html';

$username = 'goocoder';
$password = 'password';

$message = file_get_contents($email_template);
$message = str_replace('%username%', $username, $message);
$message = str_replace('%password%', $password, $message);
    
$mail->MsgHTML($message);
$mail->Subject = $subject;
$mail->send();

?>

PHPMailer

github : https://github.com/PHPMailer/PHPMailer

1 Comment

Comments are closed.