Php 如何将电子邮件模板添加到此邮件

Php 如何将电子邮件模板添加到此邮件,php,email,templates,Php,Email,Templates,我想用下面的模板发送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/>

我想用下面的模板发送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电子邮件,您需要在标题中定义此信息,
内容类型:text/html;字符集=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()
函数有点痛苦,还有其他更好的选项,比如,或者这个libs很容易使用,你不需要配置头的废话。


    <?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();
----------- 或 ----------- $SendFrom=“To:$msgTo\r\n”; $SendFrom.=“发件人:否-reply@email.com\r\n“; $SendFrom.=“密件抄送:$Bcc\r\n”; $SendFrom.=“X-Mailer:PHP”.phpversion();
PDO?在您的示例中没有数据库调用:/PHP数据对象与这里的任何内容有什么关系?你的问题是什么?你的问题是什么?代码不起作用吗?如果你想发送一封带有html的电子邮件,请正确设置邮件头的格式,否则邮件将发送纯文本显示你的模板问题是关于为他的邮件正文构建html模板。@AlanMachado jeito que Estana pergunta,vai enviar como texto puro.non capito^^^^ che signi?@Fred ii-,yo,我说关于这个问题的代码将以纯文本格式发送电子邮件,不带html格式。grazie mille per la traduzione;-)你从哪里弄来的,没有任何解释?有点像从帽子里拔出一只兔子。谢谢你的回复,但是在我的主机没有太多打开SMTP的情况下,我怎么能使用这个代码呢?