简体   繁体   English

CodeIgniter 中的 SMTP 邮件错误:服务器可能未配置为发送邮件

[英]SMTP mail error in CodeIgniter : server might not be configured to send mail

I am trying to send SMTP email using CodeIgniter, but I'm getting error in response ...我正在尝试使用 CodeIgniter 发送 SMTP 电子邮件,但在响应中出现错误...

" The following SMTP error was encountered: 0 Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. " "遇到以下 SMTP 错误:0 无法使用 PHP SMTP 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。 "

User-Agent: CodeIgniter
Date: Tue, 13 Dec 2016 07:06:56 +0000
From: "Blabla" <xxxxxxxxxxxxxx>
Return-Path: <xxxxxxxxxxxxxxxxxxx>
To: xxxxxxxxxxxx
Reply-To: "Explendid Videos" <xxxxxxxxxxxxxxxxxx>
Subject: =?utf-8?Q?=54=68=69=73=20=69=73=20=61=6E=20=65=6D=61=69=6C=20=74=65=73=74?=
X-Sender: bttvsupport@cloudlink.co.in
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <584f9e1023f2f@xxx.co.in>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_584f9e1023f99"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_584f9e1023f99
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

It is working. Great!


--B_ALT_584f9e1023f99
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

It is working. Great!

--B_ALT_584f9e1023f99--

Code is代码是

$ci = get_instance();
        $ci->load->library('email');
        $config = array();
        $config['protocol'] = "smtp";
        $config['smtp_host'] = "xxxxx";
        $config['smtp_port'] = 25;
        $config['smtp_user'] = "xxxxx"; 
        $config['smtp_pass'] = "xxxxx";
        $config['charset'] = "utf-8";
        $config['mailtype'] = "html";
        $config['newline'] = "\r\n";

        $ci->email->initialize($config);

        $ci->email->from('xxxxx', 'Blabla');
        $list = array('xxxxx');
        $ci->email->to($list);
        $this->email->reply_to('xxxxx', 'Explendid Videos');
        $ci->email->subject('This is an email test');
        $ci->email->message('It is working. Great!');
        if($ci->email->send()){echo "send";}else{echo "error ";print_r($ci->email->print_debugger());}

I think you need to load the email library in constructor like我认为您需要在构造函数中加载电子邮件库,例如

$this->load->helper(array('email')); $this->load->helper(array('email')); $this->load->library(array('email')); $this->load->library(array('email'));

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Dispatch extends MY_Controller 
{

        function __construct() {
                        parent::__construct();
                        $this->load->helper('url');
                        $this->load->helper(array('form', 'url'));
                        $this->load->library('form_validation');
                        $this->load->library('session');
                        $this->load->helper(array('email'));
                        $this->load->library(array('email'));

        }

public function sendEmail()
    {
$config = array(
    'protocol'  => 'smtp',
    'smtp_host' => 'smtp.googlemail.com',
    'smtp_port' => '587',
    'smtp_user' => 'test@gmail.com',
    'smtp_pass' => 'XXXXXXX',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
$message2 = '
    <html>
        <head>
            <title>Dispatch</title>
        </head>
        <body>






        Test Mail




        </body>
    </html>
    ';
         $subject="Test Email";
         $message=$message2;
          $this->email->from('test@gmail.com');
          $this->email->to($test@gmail.com);
          $this->email->subject($subject);
          $this->email->message($message);
          if($this->email->send())
         {
                 echo "<script type='text/javascript'>alert('Email Send Success');</script>";
                 redirect('/Dispatch/', 'refresh');
         }
         else
        {
         show_error($this->email->print_debugger());
        }

    }

}

?>

I am also facing same problem but when I try to load library in constructor the email send success.this is work for me hope this will help you too.我也面临同样的问题,但是当我尝试在构造函数中加载库时,电子邮件发送成功。这对我有用,希望这也能帮助你。

public function send_mails(){

    $config['useragent'] = 'CodeIgniter';
    $config['protocol'] = 'https';
    $config['smtp_host'] = 'smtp.gmail.com';
    $config['smtp_port'] = '587';
    $config['smtp_user'] = 'youremail@gmail.com';
    $config['smtp_pass'] = '*********';
    $config['wrapchars'] = 76;
    $config['mailtype'] = 'html';
    $config['charset'] = 'iso-8859-1';
    
    $this->load->library('email', $config);

    $from_email = "youremail@gmail.com";
    $to_email = "reseiver@gmail.com";
    //Load email library
    $this->load->library('email');
    $this->email->initialize($config);
    //$this->load->library('email', $config);
    $this->email->from($from_email, 'Identification');
    $this->email->to($to_email);
    $this->email->subject('Send Email Codeigniter');
    $this->email->message('The email send using codeigniter library');
    //Send mail
    if($this->email->send())
       echo "mail sent";
    else
      show_error($this->email->print_debugger());
    

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CodeIgniter中的AWS SMTP邮件错误(无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。) - AWS SMTP mail error in CodeIgniter (Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.) Codeigniter:您的服务器可能未配置为使用此方法发送邮件。 无法使用 PHP SMTP 发送电子邮件 - Codeigniter: Your server might not be configured to send mail using this method. Unable to send email using PHP SMTP Codeigniter 3 无法使用 PHP ZC2239A92BDE29F0A00F9173193CC2FE 发送 email。 您的服务器可能未配置为使用此方法发送邮件 - Codeigniter 3 Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method 无法使用codeigniter发送电子邮件-错误:您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using codeigniter-Error:Your server might not be configured to send mail using this method 服务器可能未配置为使用此方法发送邮件 - server might not be configured to send mail using this method 无法使用 PHP SMTP 发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using PHP SMTP. Your server might not be configured to send mail using this methods 无法使用 PHP SMTP 发送 email。您的服务器可能未配置为使用此方法发送邮件 - Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method 遇到错误无法使用 PHP mail() 发送 email。 您的服务器可能未配置为使用此方法发送邮件 - An Error Was Encountered Unable to send email using PHP mail(). Your server might not be configured to send mail using this method 无法发送AUTH LOGIN命令。 错误:无法使用PHP SMTP发送电子邮件。 您的服务器可能未配置为使用此方法发送邮件 - Failed to send AUTH LOGIN command. Error: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method CodeIgniter中的SMTP邮件错误 - SMTP mail error in CodeIgniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM