php脚本发送邮件

第一天在简书写东西,就随便写点吧………(写的不是很专业,不要嫌弃………)
-----------------------------我是分割线--------------------------------
在百度上面搜索发现基本上每个人用的方法都不一样,一般github的东西会比较好用,来给你们安利!项目地址https://github.com/PHPMailer/PHPMailer 复制这个地址,然后在终端:git clone https://github.com/PHPMailer/PHPMailer 就可以把它下到当前目录

在这个PHPMailer目录下,新建一个text.php文件,内容:

<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;                              // Enable verbose debug output
$mail->isSMTP();                                      // �使用SMTP协议
$mail->Host = 'smtp.qq.com';  // qq邮箱的服务器端地址
$mail->SMTPAuth = true;                              //SMTP 授权
$mail->Username = '要发送端邮箱@qq.com';                // 配置发送邮箱的用户
$mail->Password = '�mima';                          // 配置发送端邮箱密码
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    //qq邮箱的ssl的端口是465
$mail->setFrom('发送端邮箱@qq.com', 'Mailer');    //发送地址,昵称
$mail->addAddress('接收邮箱@qq.com', 'Joe User');    // 接收地址,昵称
// $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**in bold!**';
$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';
}
?>

-----------------------分割线---------------------

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,705评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • 大汗淋漓的运动过后,驱散的是近日不顺的阴霾,却还一份宁静于混乱的内心。剧烈跳动的心脏,将所有的不快和孤独都离心了出...
    爱锻炼的猫小二阅读 211评论 0 0
  • 我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而AOP的原...
    Stringer阅读 281评论 0 0
  • 夏天时同学聚会,一进门碰见桃子,她冲我腼腆地笑了笑,我在她身边坐下和她说话。 我们好多年不见了,她没甚变化只是更瘦...
    陈阿咪写作营阅读 432评论 1 3