成功发送邮件历程:
http://www.thinkphp.cn/code/download/id/989.html
1.以上文件放在
\ThinkPHP\Library\Vendor
2.在
\Application\Home\Common
下按照教程创建function.php
这里注意 function.php中内容有更改 官方未添加加密模式和端口所以在使用过程中一只返回false
更改内容为:
作者在下载的文件夹中阅读了一下README.md文件 发现有全部的代码:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; //
启用详细调试输出
$mail->isSMTP(); //
设置使用SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; //
指定主和备份的SMTP服务器。
$mail->SMTPAuth = true; //
使SMTP认证
$mail->Username = 'user@example.com'; //
SMTP用户名
$mail->Password = 'secret'; //
SMTP密码
$mail->SMTPSecure = 'tls'; //
启用TLS加密,“ssl”也被接受。
$mail->Port = 587; //
连接到TCP端口
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User'); //
增加一个收件人
$mail->addAddress('ellen@example.com'); //
名称是可选的
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); //
添加附件
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //
可选的名字
$mail->isHTML(true); //
将电子邮件格式设置为HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
参照以上代码, 添加以下代码进行端口设置, 添加之后便可以发送邮件 代码返回true
tls -----25
ssl ------465
$mail->SMTPSecure = 'tls'; //
启用TLS加密,“ssl”也被接受。
$mail->Port = 25; //
连接到TCP端口