温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

thinkphp中怎么利用nettemail发送邮件

发布时间:2021-06-29 16:55:13 来源:亿速云 阅读:210 作者:Leah 栏目:大数据

这期内容当中小编将会给大家带来有关thinkphp中怎么利用nettemail发送邮件,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

<?php
namespace crmeb\services;
use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;
use Nette\Utils\AssertionException;
use think\Exception;

class Email {

    // SMTP服务器
    private $server="smtp.163.com";


    // SMTP服务器的用户邮箱
    private $email="";

    //SMTP服务器的用户帐号
    private $username="";

    //SMTP服务器的授权码
    private $password="";

    // 发件人姓名
    private $name = '';

    public function __construct() {
     
    }


    /**
     * send: 发送邮件
     * @param string $accept 接收人
     * @param string $title 邮件标题
     * @param string $content 邮件内容
     * @return bool 发送成功返回true
     */
    public function send($accept, $title, $content,$file) {
       
        $mail = new Message();
        try {
            $mail->setFrom($this->name . ' <' . $this->email . '>')
                ->addTo($accept)
          
                ->setSubject($title)
                ->setBody($content)
                ->AddAttachment($file,'资料');

            $mailer = new SmtpMailer([
                'host'     => $this->server,
                'username' => $this->username,
                'password' => $this->password,
                'secure'=>'ssl',
                'port'=>465
            ]);
           $res= $mailer->send($mail);
            return true;
        } catch (AssertionException $e) {
            return false;
        }
    }
}

上述就是小编为大家分享的thinkphp中怎么利用nettemail发送邮件了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI