zoukankan      html  css  js  c++  java
  • phpmailer 发送邮件

    <?php
    /*
    可用新浪和网易邮箱测试成功,但QQ不成功!
    下载 phpmailer 解压
    http://phpmailer.worxware.com/
    
    要注意邮件服务器的端口号,默认是 25 不用修改,如果不是则要修改如下,在$mail->IsSMTP() ;下一行加上 $mail->Port = 端口号;
    */
    require 'class.phpmailer.php';
    
    $mail = new PHPMailer;
    
    $mail->IsSMTP();   // Set mailer to use SMTP
    
    $mail->Host = 'smtp.sina.com';  // SMTP 服务器 Specify main and backup server
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'mysina';                            // SMTP username
    $mail->Password = '******';                           // SMTP password
    $mail->SMTPSecure = '';                            // Enable encryption, 'ssl' also accepted
    
    $mail->From = 'mysina@sina.com';
    $mail->FromName = 'mysina';
    $mail->AddAddress('0000000@qq.com', 'Josh Adams');  // Add a recipient
    //$mail->AddAddress('ellen@example.com');               // Name is optional
    $mail->AddReplyTo('mysina@sina.com', 'Information');
    //$mail->AddCC('cc@example.com');
    //$mail->AddBCC('bcc@example.com');
    
    $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    //$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;
       exit;
    }else{
         echo 'Yes';
    }
    

      

  • 相关阅读:
    Requests发送带cookies请求
    Python3 + requests + unittest接口测试
    「完结篇」网络爬虫+实时监控+推送微信
    「爬虫」从某网站爬取数据
    定时从某网站爬取压缩包
    如何转载文章...............
    数据库连接远程服务器报错
    记录常用的Java方法
    链接服务器 不同服务器查询,插入数据
    【学习笔记】树状数组
  • 原文地址:https://www.cnblogs.com/lin3615/p/3603925.html
Copyright © 2011-2022 走看看