我正在使用代码点火器
我在实时服务器上执行了代码。使用print_debugger()时出现以下错误
无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。
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);
}
}
8条答案
按热度按时间kd3sttzy1#
将
smtp_port
从465更改为587。确保
$config['newline'] = "\r\n";
用双引号而不是单引号括起来。eimct9ow2#
我刚加了最后一行
o0lyfsai3#
出现此问题的常见原因是CodeIgniter与SMTP服务器在换行符方面的交互方式。您的SMTP服务器可能需要
\r\n
,而CodeIgniter正在使用\n
。有一个简单的解决办法:在
$this->email->initialize()
之后,添加以下内容:这应该能让它为你工作。
xxb16uws4#
只需将“mail”用于“protocol”数组项,就可以了...
oalqel3c5#
邮件服务器看起来也是由您自己托管的,请尝试从任何电子邮件客户端发送电子邮件。如果失败-是您的邮件服务器配置有问题,而不是您粘贴的代码有问题-请检查服务器日志。
kuhbmx9i6#
我使用了很多时间在localhost中运行我的配置代码,但它总是给我一个错误(无法使用PHP SMTP发送电子邮件。您的服务器可能没有配置为使用此方法发送邮件。)
但当运行这个下面的代码在我的服务器它为我工作。
应用程序〉控制器〉发送电子邮件_控制器.php
我定义f_email和email的视图页面通过post方法。应用程序〉视图〉emailtesting.php
如果某些错误再次出现,请访问以下官方文档:
https://codeigniter.com/user_guide/libraries/email.html
gzszwxb47#
对于发现此错误的其他任何人,即使已设置了其他地方提到的设置(甚至Codeigniter 4),但仍然得到此错误,一种测试发生了什么的方法是从服务器控制台使用telnet。
telnet smtp.yourprovider.com 587
然后测试不同的供应商,看看是否工作。如果你的供应商没有,但另一个可以,那么问题是与您的供应商,你应该联系他们。如果两者都不能连接,那么你应该与您的网站主机。
5fjcxozz8#
我找到了另一个解决办法。我也有同样的问题:(Codeigniter 4和php smtp的问题),原因是我的gmail帐户的两步验证,我想从我的应用程序发送电子邮件。我修复了它从我的gmail帐户,我的应用程序的密码。它的工作,在最后。