1
votes

i m trying to send email It properly working on localhost when i live it on server it give me warning i m using codeigniter here is the code

public function send_me($from,$name,$toEmail,$subject,$msg){

    $config = Array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'xxxxxxxxxxx',//user name herer
        'smtp_pass' => 'xxxxxxxx', //password hre
        'mailtype'  => 'html',
        'charset'   => 'iso-8859-1',
        'wordwrap'  => TRUE
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from($from,$name);
    $this->email->to($toEmail);//to address here
    $this->email->subject($subject);
    $this->email->message($msg);
    if($this->email->send())
        return true;
    else
        return false;
}

and warning are

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: 1689 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846

1
use $this->email->initialize($config); instead of passing it while loading - Muhammad Raheel
can you explain this raheel shan - Faizan Khattak
simpledo therse steps $this->load->library('email'); then $this->email->initialize($config); because it produces problem while loading and passing togather - Muhammad Raheel
on local it working when i live it it give the same error of the question - Faizan Khattak

1 Answers

3
votes

I have answered several issues like this one. If your local email is working fine then follow the steps below:

To use Google SMTP in CodeIgniter you need to make 2 (two) changes into your Gmail account setting: (N.B. Please be aware that it is now easier for an attacker to break into your account -says Google)

  1. Set off 2-step Verification.
  2. Allow less secure apps: ON (or Enable)

Now use 'smtp_host' as ssl://smtp.gmail.com instead of smtp.googlemail.com

Hope upcoming users can get this help too.