【问题标题】:sendmail fails on CodeIgniter but works on CLIsendmail 在 CodeIgniter 上失败,但在 CLI 上有效
【发布时间】:2016-01-26 03:12:22
【问题描述】:

我在 CentOS 6 服务器上安装了 sendmail,它似乎运行良好,因为我可以使用 CLI 发送测试消息。

但是,当尝试使用 CodeIgniter 的电子邮件类发送测试消息时,似乎出现了一些问题。我的 email.php 配置是

$config['protocol'] = 'sendmail';
$config['mailtype'] = 'html';
$config['charset']  = 'utf-8';
$config['newline']  = "\r\n";

用于测试电子邮件的控制器:

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

    $this->email->from('your@example.com', 'from name');
    $this->email->to('someone@somewhere.com');

    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');

    $this->email->send();
    echo $this->email->print_debugger();

当我通过 CodeIgniter 发送测试消息时,我收到此错误消息

Exit status code: 71
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.

在配置中切换到 SMTP 或邮件时,我仍然收到错误。

有什么建议可以从哪里着手解决这个问题?

【问题讨论】:

  • $this->load->library('email', $config);
  • 你加载 email.php 配置文件了吗?
  • 面临类似问题。获得退出状态 64。无法打开到 Sendmail 的套接字。请检查设置。但适用于 CLI

标签: php codeigniter email centos sendmail


【解决方案1】:

试试这些。

  1. 确保将 apache 添加到 smmsp 组。

    id 阿帕奇

如果注释添加到组

usermod -g smmsp apache
  1. chmod -v 2755 /usr/sbin/sendmail.sendmail

  2. 将配置['mailpath'] 更改为 /use/sbin/sendmail.sendmail

如果这些 tweeks 不起作用,

  1. chmod 777 /var/spool/clientmqueue 这是一个安全风险link

【讨论】:

    【解决方案2】:
     $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => '******@gmail.com',
    'smtp_pass' => '**********',
    'mailtype'  => 'html', 
    'charset' => 'utf-8',
    'wordwrap' => TRUE
     );           
            //send email with #temp_pass as a link
           $this->load->library('email', $config);
           $this->email->set_newline("\r\n");
            $this->email->from('**********@gmail.com', "Title");
            $this->email->to($email);
            $this->email->subject("Added");
    
            $message = "<p>This email has been sent as a request to added</p>";
            $this->email->message($message);
            $this->email->send();
    

    【讨论】:

      【解决方案3】:

      试试这样的东西

        $this->load->library('email');
                      $config['protocol']='smtp';
                      $config['smtp_host']='your host';
                      $config['smtp_port']='465';
                      $config['smtp_timeout']='30';
                      $config['smtp_user']='your mail id';
                      $config['smtp_pass']='your password';
                      $config['charset']='utf-8';
                      $config['newline']="\r\n";
                      $config['mailtype'] = 'html';
                      $this->email->initialize($config); //intializing config array 
                      $this->email->from('your@example.com', 'Site name');
                      $this->email->to('someone@somewhere.com');
                      $this->email->subject('Mail');
                      $this->email->message('Your message');
                      $this->email->send();
      

      【讨论】:

      • “您的邮件 ID”和“您的密码”应该是什么?那些用于我的服务器或特定于 SMTP 的东西?我不记得为 SMTP 设置任何用户/密码
      • @torr 这将是您的 email_id 和密码
      • 我很抱歉 anmol 但我不听,你能解释一下吗
      • @torr 你在配置数组中设置了 smtp_host 吗??
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 2017-09-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      相关资源
      最近更新 更多