PHPMailer的多用法

PHPMailer的多用法

PHPMailer是一个用于发送电子邮件的PHP函数包.灵活性很高.需要引用require("phpmailer/class.phpmailer.php");的程序来进行使用.它可以用SMTP邮件发送,第一种是不需要用中间邮件的,代码如下:
 
 


Name:'.$Name.'
'
.'Email:'.$Email.'
'
.'Phone'.$Phone.'

 
 
';
smtp_mail("xxxxxx@qq.com", "customer information", $body, "", "Australialand");
smtp_mail_user($Email, "customer information", $body_user, "", $Name);
echo '';
?>
要记住,邮件里面的内容要用HTML包起来,不然会很容易当成是垃圾邮件.
各一种也是用SMTP发送,但是这个是要要密码的, 是要用一个邮箱做为中介传媒来发送,代码如下:
// 使用PHPMailer发送邮件实例,126邮箱
include("class.phpmailer.php"); //加载PHPMailer
include("class.smtp.php"); // 可加可不加
$mail = new PHPMailer();//将PHPMailer对象实例化
$body = $mail->getFile('contents.html');//邮件正文内容,提取html文件为其内容
$body = eregi_replace("[]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // 必填,SMTP服务器是否需要验证,true为需要,false为不需要
$mail->Host = "smtp.126.com"; //必填,设置SMTP服务器
//$mail-%26gt;Port = 25; // 设置端口
$mail->Username = username@126.com; // 必填,开通SMTP服务的邮箱;任意一个126邮箱均可
$mail->Password = "password"; //必填, 以上邮箱对应的密码
$mail->From = username@126.com; //必填,发件人Email
$mail->FromName = "Webmaster%26quot;; //必填,发件人昵称或姓名
$mail->Subject = "This is the subject%26quot;; //必填,邮件标题(主题)
$mail->AltBody = "This is the body when user views in plain text format"; //可选,纯文本形势下用户看到的内容
$mail->WordWrap = 50; // 自动换行的字数
$mail->MsgHTML($body);
$mail->AddReplyTo(username@126.com"回复邮箱地址,"Webmaster");//
$mail->AddAttachment("/path/to/file.zip"); // 添加附件
$mail->AddAttachment("/path/to/image.jpg","new.jpg"); // 添加附件
$mail->AddAddress("Sendto@gmail.com","First Last");//参数一:收信人的邮箱地址,可添加多个。参数二:收件人称呼
$mail->IsHTML(true); // 是否以HTML形式发送,如果不是,请删除此行
if(!$mail->Send()) {
echo “Mailer错误: ". $mail->ErrorInfo;
} else {
echo "邮件发送成功";
}
?>

Need a translation service?

Please enter your personal details and we will contact you shortly

Words translated by CCJK

146,096,379

We are Certified

Our Client Satisfaction

rating for previous quarte

4.00

Over 95% of our clients recommend our language services to others

Copyright © CCJK Technologies Co., Ltd. 2000-2017. All rights reserved.
TOP