0

I am trying to send email from my Codeigniter project. It worked on my localserver XAMP. But not working on online server.

showing this error...

A PHP Error was encountered Severity: Warning Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (A socket operation was attempted to an unreachable network. ) Filename: libraries/Email.php Line Number: 1690

My email config file application/config/email.php is...

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 $config['protocol']='smtp';
 $config['smtp_host']='ssl://smtp.googlemail.com';
 $config['smtp_port']='465';
 $config['smtp_timeout']='30';
 $config['smtp_user']='********@gmail.com';
 $config['smtp_pass']='*******';
 $config['charset']='utf-8';
 $config['newline']="\r\n";
 ?>

Please, Help me. Advanced thanks.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
ricky
  • 77
  • 1
  • 6
  • possible duplicate of [Sending email with gmail smtp with codeigniter email library](http://stackoverflow.com/questions/1555145/sending-email-with-gmail-smtp-with-codeigniter-email-library) – Jay Blanchard Aug 11 '15 at 18:03
  • Thanks, i've seen this.But it's not working. – ricky Aug 11 '15 at 18:05
  • A similar answer can be found [by clicking here](http://stackoverflow.com/questions/17181195/unable-to-send-email-with-codeigniter/34566226#34566226) – Siddiqui Noor Jan 02 '16 at 18:00

2 Answers2

1

If you are using your own domain name to upload the code on web then why you are using google's mail id for sending mail. Why not your own webmail?

Below code is worked for me to send mail from my own domain. write this code in your controller or just $config in your configuration and remaining code in your controller.

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'UTF-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';

$this->load->library('email', $config);

$this->email->from(ADMIN_EMAIL_ID, MY_DOMAIN);
$this->email->bcc(BCC_EMAIL_ID, MY_DOMAIN);
$this->email->to($targeEmail);
$this->email->subject(EMAIL_SUBJECT);
$this->email->message(EMAIL_MESSAGE);

if ($this->email->send())
{
   $status = 'send';
}
else
{
   $status = 'notsend';
}                
kishor10d
  • 543
  • 6
  • 24
  • Thanks, It's showing email has been sent. But did not got the email yet :) should i delete the email.php of config folder. – ricky Aug 11 '15 at 18:57
  • Can you check the junk folder of your email or just check the configuration of your server. Sometimes the $config['protocol'] and $config['mailpath'] of server is different from the provided one. – kishor10d Aug 12 '15 at 10:38
1

This means that either your DNS is not working (it doesn't know where smtp.googlemail.com is), or it does know where it is but it's not responding (unlikely), or it is responding, but your server is blocked from accessing it. It's very common for ISPs (e.g. GoDaddy) to block outbound email, anything connecting to SMTP destination ports such as 25, 465 and 587. Sometimes this restriction only applies to the PHP binary, and other programs (such as telnet) do work.

Though it's not quite the same thing, you may find the PHPMailer troubleshooting docs useful for diagnosing your problem.

Synchro
  • 35,538
  • 15
  • 81
  • 104