【问题标题】:How to format my email php mailer如何格式化我的电子邮件 php 邮件程序
【发布时间】:2012-09-15 07:44:23
【问题描述】:

当我发送带有 html 标签的电子邮件时。Gmail 也会显示标签。这是为什么呢?任何解决方案?如何根据我的代码为图片加粗文字彩色文字? 这是我的电子邮件内容代码

 smtpmailer("$email", 'website@yahoo.com', '<html><body>website.lk Password recovery', 'Password recovery','Dear "'.$name."\"\n\nUse your new password to login and reset your password as you wish.\nTo reset password go to your \"My Account\" page and click \"Change my password\"\n\n"."Here is your new password:\n\n"."Password: "."$password"."\n\nBack to get bump: www.website.lk\n\nRegards,\n website.lk Admin\n</body></html>");

$reset_msg="Recovery completed. Check your e-mail !";       
}else{
$reset_msg="Error in sending email.Try again !";

}

【问题讨论】:

    标签: html phpmailer php


    【解决方案1】:

    通过包含以下标题

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    
        $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
        $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
        $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
        $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
    
    
        mail($to, $subject, $message, $headers);
    

    来源,

    http://php.net/manual/en/function.mail.php

    如果您使用的是 PHP Mailer,

    $mail->MsgHTML($body);
    
    $mail->AddAttachment("images/image1.gif");      
    $mail->AddAttachment("images/image2.gif"); 
    

    【讨论】:

    • @LahiruChathuranga 您可能正在使用 PHPMailer,这个答案对您没有帮助,只有在您使用简单的 mail 函数时才有帮助。如果您使用的是 PHPMailer,请查看我的回答。
    【解决方案2】:

    如果您正在使用此功能:

    function smtpmailer($to, $from, $from_name, $subject, $body) { 
        global $error;
        $mail = new PHPMailer();  // create a new object
        $mail->IsSMTP(); // enable SMTP
        $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
        $mail->SMTPAuth = true;  // authentication enabled
        $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 465; 
        $mail->Username = GUSER;  
        $mail->Password = GPWD;           
        $mail->SetFrom($from, $from_name);
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->AddAddress($to);
        if(!$mail->Send()) {
            $error = 'Mail error: '.$mail->ErrorInfo; 
            return false;
        } else {
            $error = 'Message sent!';
            return true;
        }
    }
    

    然后将$mail-&gt;Body = $body;这一行改成code blow:

    $mail->MsgHTML($body);
    

    此更改将允许您通过 PHPMailer 发送 HTML 电子邮件,您还可以添加 $mail-&gt;CharSet = 'UTF-8'; 以避免将来出现特殊字符问题...

    【讨论】:

      【解决方案3】:

      使用 $mail->IsHTML(ture); 如果在 phpmailer..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-20
        • 1970-01-01
        相关资源
        最近更新 更多