Sending mail with CodeIgniter using SMTP protocol not working

拜拜、爱过 提交于 2019-12-24 07:10:37

问题


I have a problem in sending mails using CI. I used the "sendmail" protocol to send mail but it is being filtered as spam. I used the SMTP protocol to solve the problem, but it's not getting sent.

My code is as follows:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => '*******@gmail.com',
    'smtp_pass' => '********',
    'mailtype'  => 'html',
    'charset'   => 'iso-8859-1'
);

$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$message = "test mail";
$this->email->set_newline("\r\n");
$this->email->from('dsiddharth2@gmail.com', 'St. Maries');
$this->email->to("dsiddharth2@gmail.com");
$this->email->subject('Contact - St. Marians Belguam');
$this->email->message($message);
if($this->email->send())
{
    echo "mail sent successfully";
}
else
{
    show_error($this->email->print_debugger());
}

When I send the email using "smtp" protocol in CI, I get the following error:

A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)

Filename: libraries/Email.php

Line Number: 1673

and other list of errors...

I asked the server admin to enable the "openssl". It's been already taken care of and is enabled.

If you want to try it out, please visit this link and check for yourself.


回答1:


If it's not working, check your php.ini file. Change this line

;extension=php_openssl.dll

to

extension=php_openssl.dll

It means remove the comment from the line in php.ini file.



来源:https://stackoverflow.com/questions/6967625/sending-mail-with-codeigniter-using-smtp-protocol-not-working

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