由于默认虚拟空间不支持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发送邮件的更多相关文章

  1. PHP下利用PHPMailer配合QQ邮箱下的域名邮箱发送邮件(转)

    首先确定不是开启socks openssl phpinfo就可以知道 下载phpmailer   地址:https://github.com/PHPMailer/PHPMailer 下载完整, 个人和 ...

  2. PHP下利用PHPMailer配合QQ邮箱下的域名邮箱发送邮件

    作 为PHP入门开发者,常常有这种述求:自己的网站中需要添加一个使用自己的域名作为发件人邮件地址的自动发送邮件的方法,用于诸如给用户发送验证码.通知 信息等.比如:我的某个用户注册模块,需要使用reg ...

  3. linux 下 用phpmailer类smtp发送邮件始终不成功,提示:ERROR: Failed to co

    https://zhidao.baidu.com/question/509191264.html?fr=iks&word=PHPMailerSMTP+connect()+failed& ...

  4. 利用PHPMailer发送邮件时报错

    利用thinkphp集成PHPMailer发送邮件时报错:Failed to connect to server: Unable to find the socket transport “ssl” ...

  5. 使用PHPmailer发送邮件的详细代码

    一.使用PHPMailer发送邮件的原因 PHP有内置的mail()方法,但是由于一些主机空间不支持该方法,所以经常会遇到无法发送邮件的情况. 所以,可以下载PHPMailer类,实现邮件发送. 二. ...

  6. ThinkPHP 中使用 PHPMailer 发送邮件 支持163和QQ邮箱等

    [摘要]ThinkPHP是一个开源的PHP框架, 是为了简化企业级应用开发和敏捷WEB应用开发而诞生的.本文介绍ThinkPHP 中使用 PHPMailer 发送邮件. PHP是自带可以发送邮件的Ma ...

  7. PHPMailer 发送邮件(二)

    发现PHPMailer又做了较大的更新,以前发送邮件的方法已不太适用,刚好要做一个实验,需要搭建个环境,这里使用Gmail进行测试,现记录下来. 传送地址Github: PHPMailer 基本要求的 ...

  8. thinkphp使用PHPMailer发送邮件

    第一步:准备PHPMailer 使用PHPMailer发送邮件,首先下载个PHPMailer 将下载的PHPMailer放到ThinkPHP文件夹里面的ThinkPHPExtendVendor 第二步 ...

  9. PHP下利用PHPMailer

    PHPMailer有什么优点? 可运行在任何平台之上 支持SMTP验证 发送邮时指定多个收件人,抄送地址,暗送地址和回复地址:注:添加抄送.暗送仅win平台下smtp方式支持 支持多种邮件编码包括:8 ...

随机推荐

  1. Django下载中文名文件:

    Django下载中文名文件: from django.utils.http import urlquote from django.http import HttpResponse content = ...

  2. PinYinCls

    using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using S ...

  3. 【原】dnsmasq小工具

    1.介绍 DNSmasq是一个轻巧的,容易使用的DNS服务工具,它可以应用在内部网和Internet连接的时候的IP地址NAT转换,也可以用做小型网络的DNS服务. 它可以提供如下几个实用的功能: 1 ...

  4. EL表达式结合页面JSTL使用 迭代显示表格

    1.迭代显示表格 <%@ page isELIgnored="false"%><%@ taglib uri="/WEB-INF/struts-bean. ...

  5. history.back(-1)和history.go(-1)的区别

    history.back(-1):直接返回当前页的上一页,数据全部消息,是个新页面 history.go(-1):也是返回当前页的上一页,不过表单里的数据全部还在 返回到指定连接:document.l ...

  6. jdk线程的同步问题

    一.银行取款引出的问题 模拟银行取钱的例子: public class ThreadDemo06 { public static void main(String[] args) { Bank ban ...

  7. [原创] IIS7下顶级域名301跳转到WWW域名

    百度搜索了众多方法,居然没有一个全面的IIS7下301域名跳转能用的教程,最终自己研究出了个可以用的供大家参考.1.绑定域名01ruodian.cn www.01ruodian.cn到空间: 2.在I ...

  8. Vertex中实现每顶点光照的镜面高光效果

    1,基础知识讲解 一个物体在自然界会收到三种光的影响,周围的环境光.漫反射和镜面反射.那么对于计算机要想模拟现实中的光照,就应该也会实现这三种基本光照->环境光.漫反射.镜面高光.对于这三种光照 ...

  9. python中get、post数据

    方法一:urllib2 参考:http://www.cnblogs.com/chenzehe/archive/2010/08/30/1812995.html post: #!/usr/bin/pyth ...

  10. JavaWeb工作原理

    一.HTTP协议的理解 什么是HTTP协议 HTTP是一种超本文传输协议,是一套计算机在网络中通信的规则.他是一种无状态的传输方式. HTTP协议的格式 HTTP的请求: 请求行(HTTP方法.请求的 ...