PHPMailer的获取:
步骤一:使我们的QQ邮箱能够发送邮件
步骤二:使我们的PHP能够使用QQ邮箱发送邮件
PHPMailer需PHP的socket扩展支持,而PHPMailer链接qq域名邮箱时需要ssl加密方式,固php还得openssl的支持,可以查看phpinfo,如下两项均存在则可以使用,其中openssl版本号之类不用管;许多虚拟主机中的php是不支持openssl扩展的,那你可能就悲剧了.
步骤三:将PHPMailer做一定的处理
/*发送邮件方法
*@param?$to:接收者?$title:标题?$content:邮件内容
*@return?bool?true:发送成功?false:发送失败
*/function?sendMail($to,$title,$content){?//引入PHPMailer的核心文件?使用require_once包含避免出现PHPMailer类重复定义的警告
require_once("phpmailer/class.phpmailer.php");?
require_once("phpmailer/class.smtp.php");?//实例化PHPMailer核心类
$mail?=?new?PHPMailer();?//是否启用smtp的debug进行调试?开发环境建议开启?生产环境注释掉即可?默认关闭debug调试模式
$mail-SMTPDebug?=?1;?//使用smtp鉴权方式发送邮件
$mail-isSMTP();?//smtp需要鉴权?这个必须是true
$mail-SMTPAuth=true;?//链接qq域名邮箱的服务器地址
$mail-Host?=?'smtp.qq.com';?//设置使用ssl加密方式登录鉴权
//?$mail-Helo?=?'Hello?smtp.qq.com?Server';
//设置发件人的主机域?可有可无?默认为localhost?内容任意,建议使用你的域名
$mail-FromName?=?'LSGO实验室';?//smtp登录的账号?这里填入字符串格式的qq号即可
$mail-Password?=?'sqyofzbqlfkntbncl';?//设置发件人邮箱地址?这里填入上述提到的"发件人邮箱"
$mail-isHTML(true);?
//设置收件人邮箱地址?该方法有两个参数?第一个参数为收件人邮箱地址?第二参数为给该地址设置的昵称?不同的邮箱系统会自动进行处理变动?这里第二个参数的意义不大
$mail-addAddress($to,'lsgo在线通知');?//添加多个收件人?则多次调用方法即可
//添加该邮件的主题
$mail-Subject?=?$title;?//添加邮件正文?上方将isHTML设置成了true,则可以是完整的html字符串?如:使用file_get_contents函数读取本地的html文件
$mail-Body?=?$content;?//为该邮件添加附件?该方法也有两个参数?第一个参数为附件存放的目录(相对目录、或绝对目录均可)?第二参数为在邮件附件中该附件的名称
//?$mail-addAttachment('./d.jpg','mm.jpg');
//同样该方法可以多次调用?上传多个附件
//?$mail-addAttachment('./Jlib-1.1.0.js','Jlib.js');
$status?=?$mail-send();?//简单的判断与提示信息
if($status)?{??return?true;
}else{??return?false;
}
}else{?echo?"发送邮件失败!";
}?
? ? ? ? "" ?
?html xmlns="" xml:lang="en" ?
?head ?
? ? titleDocument/title ?
?/head ?
body ?
?form action="mail_send.php" method="post" ?
? ? p收件人:input type="text" name="address" //p ?
? ?p标 ?题:input type="text" name="title" //p ?
?p发件人:input type="text" name="user" //p ?
? ? pinput type="submit" value="发送" ?//p ?
?/form ?
/body ?
/html ?
写了一个mail_send.php然后引入一个封装的类
php ?
?// 接收值 ?
?isset($_POST['address'])?$address=$_POST['address']:$address=''; ?
?isset($_POST['titles'])?$titles=$_POST['titles']:$titles=''; ?
?isset($_POST['content'])?$content=$_POST['content']:$content=''; ?
?isset($_POST['user'])?$user=$_POST['user']:$user=''; ?
? ?
?//引入类 ?
? require 'Mail.class.php'; ?
? ? ? ? if( Mail::send($titles,$contents,$user,$address)){ ?
? ? ? ? echo "发送成功"; ?
? ? ? ? ?}else{ ?
? ? ? ? ? ? ?echo "发送失败".'br'; ?
? ? ? ? ? ? echo Mail::$error; ?
? ? ? ?} ?
? ? ? //引入原来的类文件 ?
? ? require 'class.phpmailer.php'; ?
? ? class Mail { ?
? ? ? ? ? ?static public $error = ''; ?
? ? ? ? ? ?static public function send($title,$content,$user,$address){ ?
? ? ? ? ? ? ? ? ? ? $mail= new PHPMailer(); ?
? ? ? ? ? ? ? ? ? ?/*服务器相关信息*/ ?
? ? ? ? ? ? ? ? ? $mail-IsSMTP(); ? ? ? ? ? ? ? ? //设置使用SMTP服务器发送 ?
? ? ? ? ? ? ? ? ? ? $mail-SMTPAuth ?= true; ? ? ? ? ? ? ? //开启SMTP认证 ?
? ? ? ? ? ? ? ? ? ?$mail-Password ? = '******'; ? ?//发信人的邮箱密码 ?
? ? ? ? ? ? ? ? ? ? /*内容信息*/ ?
? ? ? ? ? ? ? ? ? ?$mail-IsHTML(true); ? ? ? ? ? ? ? //指定邮件格式为:html *不加true默认为以text的方式进行解析 ?
? ? ? ? ? ? ? ? ? ? $mail-FromName ? = $user; ? ? ? ? ? ?//发信人署名 ?
? ? ? ? ? ? ? ? ? $mail-Subject ? ?= $title; ? ? ? ? ? ? ? //信的标题 ?
? ? ? ? ? ? ? ? ? ?$mail-MsgHTML($content); ? ? ? ? ? ? ? ? //发信主体内容 ?
? ? ? ? ? ? ? ? ? /*发送邮件*/ ?
? ? ? ? ? ? ? ? ? ? ?$mail-AddAddress($address); ? ? ? ? ? ? ?//收件人地址 ?
? ? ? ? ? ? ? ? ? ? //使用send函数进行发送 ?
? ? ? ? ? ? ? ? ? ? if($mail-Send()) { ?
? ? ? ? ? ? ? ? ? ? ? return true; ?
? ? ? ? ? ? ? ? ? ? ?} else { ?
? ? ? ? ? ? ? ? ? ? ? ? ? self::$error=$mail-ErrorInfo; ?
? ? ? ? ? ? ? ? ? ? ? ? ?return ? false; ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ?} ?
? ? ?} ?
?
第一段:使用易网库提供的企业邮箱
第二段:使用qq邮箱
以上就是土嘎嘎小编为大家整理的php配置smtp怎么弄相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!