Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

Iam using codeigniter

I exicuted the code on live server. got the following error using print_debugger()

Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

public function sendEnquiry() {             $this->load->library('email');             $name = $this->input->post("fname");             $cemail = $this->input->post("email");             $pno = $this->input->post("phone");             $message = $this->input->post("message");             $config['protocol']    = 'smtp';             $config['smtp_host']    = 'ssl://mail.gatewaykhobar.com';             $config['smtp_port']    = '465';             $config['smtp_timeout'] = '7';             $config['smtp_user']    = '***********';             $config['smtp_pass']    = '***********';             $config['charset']    = 'utf-8';             $config['newline']    = "\r\n";             $config['mailtype'] = 'text'; // or html             $config['validation'] = FALSE;              $this->email->initialize($config);             $this->email->from('info@gatewaykhobar.com','Gateway Restaurent Contact');             $this->email->to($cemail);              $this->email->subject('Gateway Restaurent Contact Enquiry');             $this->email->message($message);               $send = $this->email->send();             if($send) {                 echo json_encode("send");             } else {                 $error = $this->email->print_debugger(array('headers'));                 echo json_encode($error);             }          } 

回答1:

Change smtp_port from 465 to 587 Make sure $config['newline'] = "\r\n"; is in double quotes not single quotes



回答2:

It looks like the mail server is hosted by yourself as well, try sending email from any e-mail client. If it fails - there's a problem with your mailserver config, not the code you pasted - check the server logs.



回答3:

A common cause of this is the way that CodeIgniter interacts with the SMTP server with regards to line breaks. Your SMTP server might required \r\n and CodeIgniter is using \n.

There is an easy fix: after your $this->email->initialize(), add the following:

$this->email->set_newline("\r\n");   

That should get it working for you.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!