TP5使用PHPmailer发送邮件

将phpmailer文件夹放入extend文件夹中,修改phpmailer最后的类继承为:

class phpmailerException extends \Exception
{
    /**
     * Prettify error message output
     * @return string
     */
    public function errorMessage()
    {
        $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
        return $errorMsg;
    }
}

对目录中的文件加入命名空间namespace,在目录下创建一个Email.php文件,将testmail的代码粘贴进去,修改require后的文件名,如下:

<?php
/**
 * 发送邮件类库
 */
namespace phpmailer;
class Email
{
    public static function send($to, $title, $content)
    {
       //testmail 中的代码;

}

按需求修改Email中的参数,例如SMTP的用户名密码等。

在控制器中引用类中的方法:

 \phpmailer\Email::send

猜你喜欢

转载自blog.csdn.net/honkkki/article/details/80517849
今日推荐