由于默认虚拟空间不支持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. [SQL]select scope_identity()传回插入相同范围之识别资料行中的最后一个识别值

    传回插入相同范围之识别资料行中的最后一个识别值.范围是一个模组:预存程序.触发程序.函数或批次.因此,如果两个陈述式在相同预存程序.函数或批次中,它们就在相同范围中. 语法: SCOPE_IDENTI ...

  2. linux入门学习1

    推荐 实验楼网站 在线的linux环境和课程学习 这是一些摘要和笔记 UNIX/Linux历史简介 操作系统始于二十世纪 50 年代,当时的操作系统能运行批处理程序.但是不能实现交互.交互式操作系统也 ...

  3. java 错误之:Exception in thread "main" java.lang.NoClassDefFoundError

    Exception in thread "main" java.lang.NoClassDefFoundError: PointTest 环境变量的问题,把环境变量设置好了就可以了 ...

  4. nyoj 68 三点顺序

    点击打开链接 三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给 ...

  5. WPF更新数据源

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windo ...

  6. 用js控制选项卡的隐藏与显示

    通过使用ul和div来,借助于jquery来实现选项卡的显示与隐藏 <form action="" method="post"> <div&g ...

  7. JavaScript对象的创建之外部属性定义方式(基于已有对象扩充其属性和方法)

    var person = new Object(); person.name = "luogk"; person.age = 33; person.say = function() ...

  8. 剑指Offer:面试题7——用两个栈实现队列(java实现)

    题目描述:用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 首先定义两个栈 Stack<Integer> stack1 = new Stack<I ...

  9. telnet登录路由器启动服务的shell脚本

    因为在测试中经常要telnet登录到路由器中去配置环境启动路由器,每次都输入一遍命令太麻烦了,想着写一个shell脚本实现自动登录.配置环境.启动服务的过程. 脚本实现是使用expect来实现的,所以 ...

  10. im4java开发向导

    0.搜索ImageMagick下载安装 1.Setting up the Environment    引入im4java到classpath    设置图片处理引擎的command searchpa ...