1

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.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
siddharth
  • 231
  • 1
  • 4
  • 14
  • Try using sendmail instead of smtp see how that works. – Brad Aug 06 '11 at 21:51
  • Yeah I tried using sendmail but its getting sent as "spam". I want it to appear in inbox. What are the conditions that tell gmail that a particular mail is a spam..? Thanks for answering Brad. Any other option that i can try..? – siddharth Aug 07 '11 at 03:53
  • I am not sure, sendmail works perfectly for me but I am using my websites email. I could never get stmp to work no matter what I tried. I think Nettuts did a tut on this once. Check this out http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-3/ I thin k they used Gmail – Brad Aug 08 '11 at 03:07
  • Hi @Brad i did try their mail code and it worked on my other project(on some other server). But in this its not working, Is there any option in cPanel that i need to set or something..??? Thanks in advance – siddharth Aug 08 '11 at 17:15
  • I dont think there is, Im not sure what you can do at this point. All I can say is triple check your settings to make sure nothing is wrong. I did get a Message successfully sent when I tried it – Brad Aug 08 '11 at 23:34
  • Hi..Yeah I had to show the demo to my manager so i implemented the sendmail protocol for now..But when i use smtp it is not working..I Have asked the problem to the server admin he may give me a solution. Thanks for replying. If i find any solution i will post back here.. – siddharth Aug 09 '11 at 03:33
  • Hi..I informed the server admin in which my site is hosted. And now if i use simple "mail" protocol of codeIgniter it is sending to the inbox of the user..:-) thanks for helping Brad. – siddharth Aug 28 '11 at 14:59

1 Answers1

0

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.

Gourav
  • 813
  • 2
  • 10
  • 23