如何添加电子邮件模板此消息


How to add email template this message

我想用模板发送php邮件下面是我的代码

    <?php 
    // sending email
$SendFrom = "MyWebsite <no-reply@mywebsite.com>";
$SendTo = "$user_email";
$SubjectLine = "Welcome Email Activation";
// Build Message Body from Web Form Input
$MsgBody='Hello, <br/> <br/> Your are most welcome to Mywebsite.com<br/> <br/> Before you continue kindly activate your email by clicking on the below link or copy and paste it in your browser and hit enter for your email activation to take place.<br/> <br/> <a href="'.$base_url.'activation/index.php?code='.$activation.'">'.$base_url.'activation/index.php?code='.$activation.'</a>';
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
    ?>

请注意,我使用一个简单的php代码,而不是PDO,因为它是为我工作谢谢,任何帮助都将不胜感激。

要在电子邮件中显示html,您需要在标题Content-type: text/html; charset=utf-8

中定义此信息
$headers = "From: no-reply@mywebsite.com" . "'r'n";
$headers .= 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=utf-8' . "'r'n";
mail($SendTo, $SubjectLine, $MsgBody, $headers);

mail()功能有点痛苦,有其他更好的选择,如PHPMailer或swiftmailer这个库很容易使用,你不需要配置头废话

    <?php
    function sendEmail(**$SendTo, $SubjectLine, $MsgBody,$SendFrom**)
    {
        $mail = null;
        $mail = new PHPMailer(true);
        $mail->IsSMTP();
        try
        {
            $mail->Host = "Host Name Enter"; // SMTP server
            $mail->SMTPDebug = 0;                     // enables SMTP debug information (for testing)
            $mail->SMTPAuth = true;                  // enable SMTP authentication
            // sets the SMTP server
            $mail->Port = 2525;                    // set the SMTP port for the GMAIL server
            $mail->Username = "Enter SMTP Username"; // SMTP account username
            $mail->Password = "Enter Password";        // SMTP account password
            $mail->AddAddress($SendTo);
            $mail->SetFrom($SendFrom, 'Subject To'**);
            $mail->Subject = $subject;
    //                $mail->AddEmbeddedImage('uploads/'.$res['user_img'], 'prf');
    //                                <img height='100' width='100' style='border 5px solid gray;' `enter code here`src='cid:prf' alt='' />
            $mail->MsgHTML($MsgBody);
            return $mail->Send();
        } catch (Exception enter code hereon $e)
        {
            echo $e;
        }
        $mail->ClearAllRecipients();
    }
    ?>
-----------
OR
-----------
$SendFrom = "To: $msgTo'r'n";
$SendFrom .= "From: no-reply@email.com'r'n";
$SendFrom .= "Bcc: $bcc'r'n";
$SendFrom .= "X-Mailer: PHP".phpversion();