命令行运行报错,求解决方法

浏览:717 发布日期:2018/01/08 分类:求助交流
[root@localhost study.tp5]# php think kun                      
  [think\exception\ErrorException]  
  mb_strlen(): Unknown encoding ""             
命令行文件代码 /**
     * 执行指令
     * @param Input $input
     * @param Output $output
     */
    protected function execute(Input $input, Output $output)
    {
        while (true){
            $output->writeln((new Redissendmail())->send());
            $output->writeln('--------------------------------------------------');
            sleep($this->sleep);
        }

    }
命令行所用到的方法public function send()
    {
        $pop_json = $this->redis->leftPop($this->key);
        if ($pop_json){
            $pop = json_decode($pop_json, true);
            $i = $pop['i'];
            $to = $pop['to'];
            $content = $pop['content'];
            $title = $pop['title'];
            $sendResult = $this->mail->send($to,$title,$content);
            if ($sendResult){
                return $i.'发送成功';
            }else{
                if ($this->redis->rightPush($this->key, $pop_json)){
                    return $i.'重新添加队列成功'.$pop_json;
                }else{
                    return $i.'重新添加队列失败'.$pop_json;
                }
            }
        }else{
            return '没有数据';
        }
    }
发送邮件的方法<?php
/**
 * Created by PhpStorm.
 * User: home
 * Date: 18-1-8
 * Time: 上午11:52
 */

namespace app\api\controller;


use PHPMailer\PHPMailer\PHPMailer;

class SendMail
{
    //实例化对象
    private $mail;

    //smtp服务器名称
    private $mail_host;
    //启用smtp认证
    private $mail_smtpauth;
    //邮箱名
    private $mail_username;
    //邮箱授权码
    private $mail_passwd;
    //发件人地址
    private $mail_from;
    //发件人姓名
    private $mail_fromname;
    //是否html格式邮件
    private $mail_ishtml;
    //设置邮件编码
    private $mail_charset;


    public function __construct()
    {
        $mailConfig = config('mail');
        //smtp服务器名称
        $this->mail_host = $mailConfig['MAIL_HOST'];
        //开启smtp
        $this->mail_smtpauth = $mailConfig['MAIL_SMTPAUTH'];
        //发件人地址
        $this->mail_from = $mailConfig['MAIL_FROM'];
        //发件人姓名
        $this->mail_fromname = $mailConfig['MAIL_FROMNAME'];
        //邮箱用户名
        $this->mail_username = $mailConfig['MAIL_USERNAME'];
        //邮箱授权码
        $this->mail_passwd = $mailConfig['MAIL_PASSWORD'];
        //是否html格式
        $this->mail_ishtml = $mailConfig['MAIL_ISHTML'];
        //设置邮件编码
        $this->mail_charset = $mailConfig['MAIL_CHARSET'];

        $this->mail = $this->MailConnect();

    }

    /**
     * 实例化phpmailer对象
     * @return PHPMailer
     */
    public function MailConnect()
    {
        //实例化
        $mail = new PHPMailer();
        //开启smtp
        $mail->isSMTP();
        //smtp服务器名称
        $mail->Host = $this->mail_host;
        $mail->SMTPAuth = $this->mail_smtpauth;
        //邮箱用户名
        $mail->Username = $this->mail_username;
        //邮箱授权码
        $mail->Password = $this->mail_passwd;
        //发件人地址
        $mail->From = $this->mail_from;
        //发件人姓名
        $mail->FromName = $this->mail_fromname;
        //设置每行字符长度
        $mail->WordWrap = 50;
        //设置邮件编码
        $mail->CharSet = $this->mail_charset;
        //是否html格式
        $mail->isHTML($this->mail_ishtml);
        //返回对象
        return $mail;
    }


    public function send($to, $title, $content)
    {

        // todo 邮箱验证;

        //收信箱地址
        $this->mail->addAddress($to);
        //邮件主题
        $this->mail->Subject = $title;
        //邮件内容
        $this->mail->Body = $content;

        $this->mail->Debugoutput = 'echo';

        $this->mail->SMTPDebug = 4;

        $sendMailResult = $this->mail->send();

        var_dump($sendMailResult);

//        return $sendMailResult;

    }




}
最佳答案
评论( 相关
后面还有条评论,点击查看>>