php下使用phpmailer发送邮件
由于默认虚拟空间不支持mail()函数,客户需要留言发送邮件,找到phpmailer发送不成功,调试成功后记录一下。
最新的下载地址在github,https://github.com/Synchro/PHPMailer
使用很简单,但我遇到三个问题。
1、Gmail开通了两步验证的同学,需要生成一个app专业密码,使用它,开启SSL,端口号是465
2、QQ邮箱需要申请密保后才能开启SMTP等服务,所以在qq邮箱后台没有开启服务的当然是发不出邮件的
下面是以GMAIL测试的发送代码
<?php
require 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com;'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'luwenjie110@gmail.com'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to $mail->setFrom('luwenjie110@gmail.com', 'Mailer');
$mail->addAddress('269811553@qq.com', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com'); //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to 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';
}
3、本地调试ok,上传到虚拟空间后出错:Parse error: syntax error, unexpected T_FUNCTION class.phpmailer.php on line 3040
google 后知道问题出在php版本上:https://github.com/PHPMailer/PHPMailer/issues/535
将西数空间php调成5.5没报错但还是无法发送邮件,继续调成5.3则正常了。但多次测试后还是大多数时间发送超时,折腾了很久以为是跟页面js有冲突,没加载完等原因。
其实最后还是想到了是gmail不稳定的原因,在国内就是这样,最后改用qq邮箱,效果非常好。
完结!
php下使用phpmailer发送邮件的更多相关文章
- PHP下利用PHPMailer配合QQ邮箱下的域名邮箱发送邮件(转)
首先确定不是开启socks openssl phpinfo就可以知道 下载phpmailer 地址:https://github.com/PHPMailer/PHPMailer 下载完整, 个人和 ...
- PHP下利用PHPMailer配合QQ邮箱下的域名邮箱发送邮件
作 为PHP入门开发者,常常有这种述求:自己的网站中需要添加一个使用自己的域名作为发件人邮件地址的自动发送邮件的方法,用于诸如给用户发送验证码.通知 信息等.比如:我的某个用户注册模块,需要使用reg ...
- linux 下 用phpmailer类smtp发送邮件始终不成功,提示:ERROR: Failed to co
https://zhidao.baidu.com/question/509191264.html?fr=iks&word=PHPMailerSMTP+connect()+failed& ...
- 利用PHPMailer发送邮件时报错
利用thinkphp集成PHPMailer发送邮件时报错:Failed to connect to server: Unable to find the socket transport “ssl” ...
- 使用PHPmailer发送邮件的详细代码
一.使用PHPMailer发送邮件的原因 PHP有内置的mail()方法,但是由于一些主机空间不支持该方法,所以经常会遇到无法发送邮件的情况. 所以,可以下载PHPMailer类,实现邮件发送. 二. ...
- ThinkPHP 中使用 PHPMailer 发送邮件 支持163和QQ邮箱等
[摘要]ThinkPHP是一个开源的PHP框架, 是为了简化企业级应用开发和敏捷WEB应用开发而诞生的.本文介绍ThinkPHP 中使用 PHPMailer 发送邮件. PHP是自带可以发送邮件的Ma ...
- PHPMailer 发送邮件(二)
发现PHPMailer又做了较大的更新,以前发送邮件的方法已不太适用,刚好要做一个实验,需要搭建个环境,这里使用Gmail进行测试,现记录下来. 传送地址Github: PHPMailer 基本要求的 ...
- thinkphp使用PHPMailer发送邮件
第一步:准备PHPMailer 使用PHPMailer发送邮件,首先下载个PHPMailer 将下载的PHPMailer放到ThinkPHP文件夹里面的ThinkPHPExtendVendor 第二步 ...
- PHP下利用PHPMailer
PHPMailer有什么优点? 可运行在任何平台之上 支持SMTP验证 发送邮时指定多个收件人,抄送地址,暗送地址和回复地址:注:添加抄送.暗送仅win平台下smtp方式支持 支持多种邮件编码包括:8 ...
随机推荐
- Java中的大数处理类BigInteger和BigDecimar浅析
这两个类位于java.math包内,要使用它们必须在类前面引用该包:import java.math.BigInteger;和import java.math.BigDecimal; BigInteg ...
- 如何让Form窗体接收KeyDown事件?
在使用.Net Framework编写窗体应用程序的时候,有时有需要响应窗体的按键消息.当窗体上没有任何其他控件的时候,窗体是可以直接响应这些消息的. 但是当窗体上有其他控件时,会发现窗体再也不会响应 ...
- SQL SERVER系统表
sysaltfiles 主数据库 保存数据库的文件 syscharsets 主数据库 字符集与排序顺序sysconfigures 主数据库 配置选项syscurconfigs 主数据库 当前配置选项s ...
- nginx 状态码整理
状态代码 状态信息 含义 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分.(HTTP 1.1新)101 Switching Protocols 服务器将遵从 ...
- JDBC数据更新
在JDBC中通常用Statement类的对象实现对数据库的更新(增.删.查.改)操作 //1.获取数据库连接 connection = getConnection(); //2.准备sql语句 Str ...
- vc 取windows系统信息 版本 cpu信息 内存信息 ie版本信息 office版本
头文件: /*! Copyright (C) *---------------------------------------------------------------------------- ...
- testng参数化方法:Parameters和DataProvider
Parameters注解在测试方法上指定参数列表,然后在测试方法中声明对应的形参,形参与参数列表一一对应,但名字可以不同,如下所示: public class Test1 { @Parameters( ...
- 防范ARP网关欺骗, ip mac双向绑定脚本
客户局域网内的一台数据库服务器, 重新安装操作系统后,不能上网了,ping网关192.168.0.1出现在800多ms的响应时间,还会超时丢包,检查了ip,路由配置,都没有问题.通过IE打开路由器管理 ...
- Class attributes
In order to print Card objects in a way that people can easily read, we need a mapping from the inte ...
- java.lang.IllegalArgumentException
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Persiste ...