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);
  • 相关阅读:
    微信公众号教程(5)自动回复操作案例
    微信公众号教程(4)微信公众平台编辑模式介绍
    微信公众号教程(3)微信公众平台群发消息
    微信公众号教程(2)微信公众平台后台介绍
    微信公众号教程(1)微信公众账号注册、设置、登陆
    二级c程序设计题(2)
    二级c程序设计题(1)
    C++经典编程题#6:分配病房
    C++经典编程题#5:寻找下标
    python-----面向对象三大特性
  • 原文地址:https://www.cnblogs.com/qq917937712/p/8881214.html
Copyright © 2011-2022 走看看