phpmailer 发送邮件

搞了挺长时间,终于在gmail上测试成功,如果有在QQ或163邮箱测试成功的,方便的话,麻烦告知详细配置。

phpmailer下载地址:

PHPMailer : https://github.com/PHPMailer/PHPMailer

一、基本要求

  • Web访问正常(apache可以正常访问)
  • php 设置正确(Sockets Support、OpenSSL support 两项设置为enable)
  • gmail设置, 允许不够安全的应用:已启用

可以写一个简单的语句测试一下:info.php

<?php
phpinfo();
?>

将下载好的phpmailer解压到web目录,我的目录结构如下:(主要的文件是红框中圈出的,目录中比你解压后多出的文件,请不要在意)

二、gmailer.php设置

标记为***xxx***的需要改成自己的信息。

<?php
require ‘PHPMailerAutoload.php‘;                    // 跟gmailer同在phpmailer文件夹下
$mail = new PHPMailer;
$mail->SMTPDebug = 1;              // 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 = ‘***[email protected]***‘;  // SMTP username
$mail->Password = ‘***your_gmail_password***‘;          // SMTP password
$mail->SMTPSecure = ‘ssl‘;          // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;               // TCP port to connect to
$mail->setFrom(‘***[email protected]***‘, ‘Mailer‘);     // Add set from id
$mail->addAddress(‘***starnight_cyber at foxmail 。 com***‘, ‘Receiver‘);        // Add a recipient
$mail->addAddress(‘***neverthinkaboutit at 163。com***‘, ‘Receiver‘);     // Add a recipient
$mail->Subject = ‘Helo, it is a test!‘;
$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‘;
}
?>

访问页面:http://localhost/phpmailer/gmailer.php, 您将得到如下输出,显示的是发送正确。(图片质量显示太差)

下面是收件人的情况:(邮件发送后,需要稍等一分钟左右可以看到邮件,用gmail会更快些)

最后,附上:Gmail,QMail,163邮箱的 IMAP/SMTP/POP3 地址

欢迎给我留言联系...

时间: 2024-08-24 02:32:48

phpmailer 发送邮件的相关文章

用phpmailer发送邮件提示SMTP Error: Could not connect to SMTP host解决办法

之前做项目的时候做了一个用phpmailer发送邮件的功能<CI框架结合PHPmailer发送邮件>,昨天步署上线(刚开始用新浪云,嫌贵,换成阿里了),测试的时候,发送邮件却意外报错了.......... 我擦,没上线的时候好好的,次次成功,刚开始我以为是smtp地址的问题(我用的163邮箱),后来改成了QQ邮箱,发现还是没有用,没办法,只好问度娘了,后来看着百度上的答案才明白除了google的smtp服务器收到请求"smtp"会接受,其他的服务器就像我用的163,QQ什么

YII 邮件发送 phpmailer发送邮件!Yii自定义类引用

第一步:下载phpmailer解压后得到以下三个文件 class.phpmailer.php class.pop3.php class.smtp.php 将class.phpmailer.php改名成phpmailer.php并把三个文件放到 /protected/extensions/PHPMailer/目录下 修改一下phpmailer.php文件,添加init方法 public static function init(){ return new PHPMailer(); } 第二步:修改

TP5使用PHPMAILER发送邮件

TP使用PHPMAILER发送邮件 1.申请一个SMTP服务的邮箱. 我申请的是smtp.163.com的服务,注意SMTP服务密码不是登陆密码,需要单独设置 2.下载phpmailer类库文件http://pan.baidu.com/s/1kUNK9vx 3.将PHPMAILER类库中的class.phpmailer.php和class.smtp.php文件取出来,并重新命名为符合tp5命名规范的Phpmailer.php和Smtp.php 4.在项目根目录下的extend文件夹中,建立php

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

一.使用PHPMailer发送邮件的原因 PHP有内置的mail()方法,但是由于一些主机空间不支持该方法,所以经常会遇到无法发送邮件的情况. 所以,可以下载PHPMailer类,实现邮件发送. 二.发送邮件的具体步骤 1.先保证发件人的邮箱开启了SMTP服务. 在这里设置,截图如下: 设置好了就接着往下看, 2.下载的PHPMailer中,拷贝class.phpmailer.php和class.smtp.php到项目目录下 sendmail.php <?php /** * 2014-08-25

Thinkphp使用PHPMailer发送邮件遇到的问题

第一次使用ThinkPHP编写”找回密码“功能,按照网上的DEMO做完后,试了好几个邮箱都不管用,试了半天终于成功了,以下是我的实现过程: 第一步:准备PHPMailer 首先下载PHPMailer扩展,谷歌一下就有了.然后将下载的PHPMailer整个文件夹放到ThinkPHP文件夹里面的Vendor目录下. 第二步:修改配置文件 向conf.php配置文件中添加以下内容: 'THINK_EMAIL' => array( 'SMTP_HOST' => 'smtp.sina.com', //S

Thinkphp3.2 PHPMailer 发送邮件

Thinkphp3.2 PHPMailer 发送邮件结合QQ企业邮箱发送邮件 下载附件PHPMailer解压到ThinkPHP\Library\Vendor 在Common文件夹新建function.php /** * 邮件发送函数 */ function sendMail($to, $title, $content) { Vendor('PHPMailer.PHPMailerAutoload'); $mail = new PHPMailer(); //实例化 $mail->IsSMTP();

利用PHPMailer发送邮件时报错

利用thinkphp集成PHPMailer发送邮件时报错:Failed to connect to server: Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP 解决办法: 1.既然是ssl错误,习惯性的从php.ini中相应行打开支持,(extension=php_openssl.dll),服务器是windows主机,重启iis发现竟然还是不支持?

PHPMailer 发送邮件(二)

发现PHPMailer又做了较大的更新,以前发送邮件的方法已不太适用,刚好要做一个实验,需要搭建个环境,这里使用Gmail进行测试,现记录下来. 传送地址Github: PHPMailer 基本要求的内容跟之前的文章是一样的: phpmailer 发送邮件(一)  一.基本要求 Web访问正常(apache可以正常访问) php 设置正确(Sockets Support.OpenSSL support 两项设置为enable) gmail设置, 允许不够安全的应用:设置为已启用 可以写一个简单的

PHPMailer发送邮件遇坑小记

一:phpmailer发送邮件成功了 数据库发送状态也更改 但是用户就是没收到邮件. 出现原因:发送邮件太多 导致邮箱服务器被腾讯封了 发送的邮件统统进入了邮件服务器的草稿箱里. 解决方案: 重新修改密码,更换授权码即可. 二:php发送邮件报错:SMTP Error: data not accepted. 出现原因:发送邮件太频繁 解决方案: 休息一天这样自己就好了. 原文地址:https://www.cnblogs.com/xinxinmifan/p/phpmailer_error.html

thinkphp中怎么使用phpmailer发送邮件

phpmailer发送邮件是php开发者首选的一个邮件发送插件了,下面我来介绍怎么集成phpmailer到thinkphp框架了,有需要了解的朋友可参考. phpmailer发送邮件功能很强大,今天真正的体验一下,简单说一下配置,本人是在thinkphp中是用的. 配置步骤: 1.后台配置发送邮件类,位置admin/common/common.php中,代码如下: function sendmail($tomail,$title,$content) { /*邮件设置信息*/ $email_set