zoukankan      html  css  js  c++  java
  • thinkphp用swiftmailer发邮件demo

    QQ邮箱

    include_once APPPATH . 'libraries/swiftmailer/swift_required.php';
    
    $transport = Swift_SmtpTransport::newInstance('smtp.qq.com', 465, 'ssl')
        ->setUsername('11111@qq.com')
        ->setPassword('asfacasafa');  //QQ邮箱授权码
    $mailer = Swift_Mailer::newInstance($transport);
    $message = Swift_Message::newInstance()
        ->setSubject('测试')
        ->setFrom(array(
            '11111@qq.com' => '牛牛',
        ))
        ->setTo(array('22222@qq.com'))
        ->setContentType('text/html')
        ->setCharset('utf-8')
        ->setBody('测试内容');
        
    var_dump($mailer->send($message));

    公司邮箱

    include_once APPPATH . 'libraries/swiftmailer/swift_required.php';  
    
    $transport = Swift_SmtpTransport::newInstance('mail.wifire.net', 587)
        ->setUsername('cccc@wifire.net')
        ->setPassword('wvasecae23');
    $mailer = Swift_Mailer::newInstance($transport);
    $message = Swift_Message::newInstance()
        ->setSubject('测试')
        ->setFrom(array(
            'cccc@fastweb.com.cn' => '云安全管理员',
        ))
        ->setTo(array('3333@qq.com'))
        ->setContentType('text/html')
        ->setCharset('utf-8')
        ->setBody('测试内容');
    
    var_dump($mailer->send($message));
    
    
    
    
    include_once APPPATH . 'libraries/swiftmailer/swift_required.php';
    $transport = Swift_SmtpTransport::newInstance('mail.wifire.net', 587)
        ->setUsername('cccc@wifire.net')
        ->setPassword('casd2323');
    $mailer =Swift_Mailer::newInstance($transport);
    $message = Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom(array('cccc@fastweb.com.cn' =>'云安全管理员'))
        ->setTo($to)
        ->setContentType('text/html')
        ->setCharset('utf-8')
        ->setBody($content);
    
    $cc != '' && $message->setCc($cc);
    $bcc != '' && $message->setBcc($bcc);
    
    return $mailer->send($message);

    163邮箱

    注意:163会自动检测内容是否是垃圾内容。测试的时候,由于标题和内容我随便填写了一下,导致邮件发送失败。

    错误码参考:http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html

    include_once APPPATH . 'libraries/swiftmailer/swift_required.php';
    
    $transport = Swift_SmtpTransport::newInstance('smtp.163.com', 25)
        ->setUsername('abc@163.com')
        ->setPassword('xuxu1016');
    $mailer = new Swift_Mailer($transport);
    $subject = "下午有事";
    $send_list = array('asd@qq.com');
    $body = "下午有事,不去上班了";
    
    $message = new Swift_Message();
    $message->setSubject($subject)
        ->setFrom(['abc@163.com' => 'xuxu'])
        ->setTo($send_list)
        ->setCharset('utf-8')
        ->setBody($body, 'text/html');
    $success = $mailer->send($message, $errorList);
    print_r($success);
  • 相关阅读:
    免费的Office批量打印工具 Word、Excel、PDF批量打印
    PHP数据库批量去注释、删字段
    SSL/TLS协议信息泄露漏洞(CVE-2016-2183)【原理扫描】
    CentOS 安装 nginx-1.19.4 与原版本共存
    毕业5年之——上个五年计划复盘20210919
    ubunt 20.04 有道词典命令行工具
    java中针对 try,catch和finally一些总结
    Linux find命令与cp命令连用
    MySQL基本操作笔记
    挖矿病毒排查
  • 原文地址:https://www.cnblogs.com/qq917937712/p/8881214.html
Copyright © 2011-2022 走看看