conposer phpmailer 发邮件

把"phpmailer/phpmailer": "~5.2"放到conposer.json下面

命令行执行conposer update  在vendor下面会出现PHPMailer文件夹

进入vendor/composer/autoload_classmap.php

复制一行

写成最后一行,然后控制器use PHPMailer;

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = ‘smtp.163.com‘;  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = ‘[email protected]‘;                 // SMTP username
        $mail->Password = ‘gzp910728‘;                           // SMTP password
        $mail->SMTPSecure = ‘tsl‘;                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 25;                                    // TCP port to connect to

$mail->setFrom(‘[email protected]‘, ‘鹏大哥‘);
        // $mail->addAddress(‘[email protected]‘, ‘鹏哥哥‘);     // Add a recipient
        $mail->addAddress(‘[email protected]‘);               // Name is optional
        $mail->addReplyTo(‘[email protected]‘, ‘鹏哥哥‘);
        // $mail->addCC(‘[email protected]‘);
        // $mail->addBCC(‘[email protected]‘);

// $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‘;
        }

时间: 2024-08-13 19:34:08

conposer phpmailer 发邮件的相关文章

ThinkPHP3.2.2整合PHPMailer发邮件

1.下载PHPMailer; 2.把class.phpmailer.php,class.smtp.php取出分别重命名为PHPMailer.class.php和SMTP.class.php; 3.并把以上两个文件放到如下图位置: 4.在Tools文件夹下建PMailer.class.php,代码如下: <?php namespace Tools; /** * PHPMailer 发邮件工具类 * @author hzd */ class PMailer { private static $Cha

phpMailer 发邮件例子、乱码、发送html内容介绍

//phpmailer代码工具类以及传到我的csdn"我的资源"中,可以带这里去下载</span> echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'; require_once("class.phpmailer.php"); //下载的文件必须放在该文件所在目录 $mail = new PHPMailer

用phpmailer发邮件 中文乱码问题解决

加入如下代码解决. $mail->CharSet = "GB2312"; //utf-8; $mail->Encoding = "base64"; <?php set_time_limit(0); include("class.phpmailer.php"); include("class.smtp.php"); $mail=new PHPMailer(); function send_email($mail

阿里云服务器不能发邮件,禁用25端口的解决办法

前阵子刚刚买了个阿里云服务器,在做发送邮件功能时,发现本来在本地测试没问题的功能,在服务器上连接超时. 后来发现是阿里云将25端口禁用了("坑!当然也有其道理"),大概2016年9月后买的服务器都被禁用.25禁用了,我们就不用它.以163邮箱为例: 网易163免费邮箱相关服务器信息: 我这里用的就是SSL协议端口465,代码如下 <?phpheader("content-type:text/html;charset=utf-8");include("

怎么使用PHPMailer实现邮件的发送??

来源:http://www.ido321.com/1103.html 发送邮件是经常使用的功能.LZ今天在项目中也碰到了,特此分享一下. 首先.去下载PHPMailer 1.https://github.com/dwqs/PHPMailer 2.http://download.csdn.net/detail/u011043843/8063583 下载之后.将文件解压到项目文件夹的相应位置,将class.phpmailer.php和class.smtp.php引入项目中,看代码:(解压的文件不要删

使用phpmailer自动邮件提醒

近期的一个小项目中需要用到邮件自动通知功能,搜了搜,发现phpmailer这个东西大家用的挺多的. 首先去sourceforge下载phpmailer,也可去我的网盘下载,我用的是5.1版本的. 看到phpmailer目录下有三个class文件,这便是phpmailer的核心,可以将这些文件拷到你的项目中. 使用起来phpmailer很方便,如下: require("class.phpmailer.php"); $mail = new PHPMailer(); //建立邮件发送类 $m

阿里云centos 7 创建postfix服务器,并进行stmp验证,并结合phpmailer进行邮件发送

由于centos默认会自带sendmail,而sendmail存在安全性问题和使用复杂的问题,故而选择postfix服务器,由于暂时没有收邮件的需求,故未安装dovecot. 1.[[email protected] ~]# yum remove sendmail -y    #卸载自带的sendmail 2.[[email protected] ~] #yuminstall postfix –y  # 安装postfix服务的主程序包 配置项如下: 1 queue_directory= /va

Linux发邮件之mail

1.安装 (需要sendmail或postfix服务) sendmail     # yum install sendmail      # systemctl start sendmail.service     # systemctl status sendmail.service postfix     # yum install mailx     # systemctl start postfix.service     # systemctl status postfix.servi

Linux发邮件

一.mail命令 1.配置 vim /etc/mail.rc 文件尾增加以下内容  set [email protected] smtp="smtp.qq.com"set smtp-auth-user="[email protected]" smtp-auth-password="123456"set smtp-auth=login 说明: from: 对方收到邮件时显示的发件人smtp: 指定第三方发送邮件的smtp服务器地址smtp-auth