【问题标题】:how to send email in codeigniter on localhost如何在本地主机上的 codeigniter 中发送电子邮件
【发布时间】:2015-11-30 12:46:11
【问题描述】:

你好,我必须在本地主机上发送电子邮件 以下是我的配置文件

$config['useragent']      = "CodeIgniter";
$config['mailpath']       = "/usr/sbin/sendmail -t -i";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'xyz.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xyz.com'; //change this
$config['smtp_pass'] = '######'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard

我为电子邮件发送代码创建代码

if(count($result) > 0 || $result != NULL){
                    $password=$result['password'];
                    $this->load->library('email');
                    $from='chirag@site.com';
                    $to=$email;
                    $subject='forget password';                        
                    $this->email->from($from);
                    $this->email->to($to);
                    $this->email->subject($subject);
                    $this->email->message($password);
                    if($this->email->send()){
                        $this->session->set_flashdata('email','We sent your password to your Email...!');
                        redirect('login');
                    }
                    else{            
                        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.

那么有什么问题吗? 请帮我解决

【问题讨论】:

  • 您的主机/用户/通行证是否有效(确定)以及尝试发送电子邮件的代码在哪里..?
  • 是的,都是有效的主机、用户、密码

标签: php codeigniter email


【解决方案1】:

首先确保您已经为sending emails 完成了正确的本地主机配置。 然后在您的控制器中通过设置适当的凭据和端口号来加载电子邮件库。像这样:

$config = Array(
                            'protocol' => 'smtp',
                            'smtp_host' => 'ssl://smtp.gmail.com',
                            'smtp_port' => 465,
                            'smtp_user' => 'your_gmail_name@gmail.com', 
                            'smtp_pass' => 'your_pass', 
                            //'mailtype' => 'html',
                            // 'charset' => 'iso-8859-1',
                            // 'wordwrap' => TRUE
                        );
                        $this->load->library('email', $config); 

【讨论】:

    【解决方案2】:

    我得到了答案 配置中缺少 ssl:// 但是在写完之后

    $config['smtp_host'] = 'ssl://xyz.com';
    

    邮件发送成功...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 2012-01-28
      • 2015-01-25
      • 2016-11-02
      • 2013-10-01
      • 2010-12-19
      相关资源
      最近更新 更多