Home Articles

sendmail在CodeIgniter上失败但在CLI上运行

Asked
Viewed 718 times
0

我有一个安装在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或邮件时,我仍然会收到错误 .

有什么建议从哪里开始尝试解决这个问题?

4 Answers

  • 0

    我没有看到您正在初始化邮件配置 . 尝试添加$ this-> email-> initialize($ config);

  • 0

    尝试这样的事情

    $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();
    
  • 0
    $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();
    
  • 0

    试试这些 .

    • 确保将apache添加到smmsp组 .

    id apache

    如果注释添加到组

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

    • 将config ['mailpath']更改为/use/sbin/sendmail.sendmail

    如果这些tweeks不起作用,

    • chmod 777 / var / spool / clientmqueue存在安全风险link

Related