使用phpmailer在php中发送html内容 [英] send html content in php using phpmailer

查看:76
本文介绍了使用phpmailer在php中发送html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在使用php邮件发送邮件。但是我需要在php邮件中发送HTML内容我提到很多网站都说IsHTML(true)函数用于在php邮件中发送HTML内容。但它不是为我工作。



这是我的编码。

 <?php  
函数smtpmailer($ to,$ to_cc,$ to_bcc,$ from,$ from_name,$ subject,$ body){
全球 $ error ;
require_once(' class.phpmailer.php');
$ mail = new PHPMailer();
$ mail-> IsSMTP(); // 告诉班级使用SMTP
$ mail-> Host = smtp.gmail.com;
$ mail-> SMTPAuth = true; // 启用SMTP身份验证
$ mail-> SMTPSecure = ssl; // 设置服务器的前缀
$ mail-> Host = smtp.gmail.com; // 将GMAIL设置为SMTP服务器
$ mail-> Port = 465 ; // 设置GMAIL服务器的SMTP端口
$ mail-> Username = < span class =code-string>
************ @ gmail.com; // GMAIL用户名
$ mail->密码= ********; // GMAIL密码
$ mail-> SetFrom($ from,$ from_name);
$ mail-> AddAddress($ to);
$ mail-> IsHTML(true);
$ mail-> Subject = $ subject ;
$ mail-> Body = $ body ;

if($ to_cc!=
{
$ mail-> AddCC($ to_cc);
}
if($ to_bcc!=
{
$ mail-> AddBCC($ to_bcc);
}

if(!$ mail-> Send()){
$ error = ' 邮件错误:'。$ mail-> ErrorInfo;
print $ error ;
return false;
} else {
$ error = ' 发送消息!';
print $ error ;
返回 true;
}
}
?>





请帮我解决这个问题。

解决方案

to,


to_cc,


to_bcc,

Hi i am using php mailer to sending mails.But i need to send the HTML content in php mail i refer lot of site all are says IsHTML(true) function is used to send HTML content in php mail.But its not working for me.

This is my coding.

<?php
function smtpmailer($to, $to_cc, $to_bcc, $from, $from_name, $subject, $body) {
global $error;
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host  = "smtp.gmail.com";
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "************@gmail.com"; // GMAIL username
$mail->Password = "********"; // GMAIL password
$mail->SetFrom($from, $from_name);
$mail->AddAddress($to);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;

if($to_cc!="")
{
$mail->AddCC($to_cc);
}
if($to_bcc!="")
{
$mail->AddBCC($to_bcc);
}

if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
print $error;
return false;
} else {
$error = 'Message sent!';
print $error;
return true;
}
}
?>



Please help me to solve this.

解决方案

to,


to_cc,


to_bcc,


这篇关于使用phpmailer在php中发送html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆