|
$this->load->library('email');
$config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.163.com'; $config['smtp_user'] = 'xxx@163.com'; $config['smtp_pass'] = 'xxx';//密码 $config['mailtype'] = 'html'; $config['validate'] = true; $config['priority'] = 1; $config['crlf'] = "\r\n"; $config['smtp_port'] = 25; $config['charset'] = 'utf-8'; $config['wordwrap'] = TRUE; $this->email->initialize($config); $this->email->from('xxx@163.com', '我是名称而已'); $this->email->to('xxx@qq.com'); $this->email->subject('文字随意'); $this->email->message('本次验证码是请在3分钟内输入'); $this->email->send(); echo $this->email->print_debugger(); 以上是我的配置,然后抱错了:The following SMTP error was encountered: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. | |
|
翻译过来的意思大致如下:
下面是遇到的SMTP错误: 无法使用PHP SMTP发送电子邮件。您的服务器可能不会被配置为使用这种方法发送邮件。 | |
|
有没有大神解答下或发下你的配置
| |
情、非得已 发表于 2017年11月9日 16:00 你看你的配置 $config['mailtype'] = 'html'; html 是要用完整的 html文件的,而你测试 确是一段文本 ,先改这个 | |
情、非得已 发表于 2017年11月29日 14:39 改成text还是错误 | |
情、非得已 发表于 2017年11月29日 14:39 好像可以了,之前是我格式拼接错误了,我在多试试看,先感谢大神 | |
情、非得已 发表于 2017年11月29日 15:13 $send_email = $this->input->post('send_email'); if (!$send_email) { dexit('邮箱不能为空'); } if (!preg_match('/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/', $send_email)) { dexit('邮箱格式有误'); } $this->load->library('email'); //加载CI的email类\ //设置发送内容 $this->email->from('18571499331@163.com', 'admin');//发送方 $this->email->to($send_email);//接收方 //$this->email->to('1025186947@qq.com');//接收方 $this->email->subject('邮箱验证码');//标题 //unset($_SESSION['email_code']); $email_code = rand(100000, 999999); $html = '<html><head></head><body>本次验证码是' . $email_code . '请在2分钟内输入</body></html>'; //$this->email->message('本次验证码是' . $email_code . '请在2分钟内输入');//主题(内容样式可自行编辑) $this->email->message($html);//主题(内容样式可自行编辑) //$this->email->send(); //echo $this->email->print_debugger(); if ($this->email->send()) {//成功返回true //echo '成功'; //$_SESSION['email_code'] = $email_code; dexit('发送成功', false, $email_code); } else { //echo '失败'; dexit('获取失败,请重新获取'); } 我现在的代码是这样的,有时候能发送成功,有时候不能,不知道为啥,如果直接不用变量发送基本没问题,但是从前台获取到的邮箱值有时候会发送失败,不知道为啥 | |