Welcome Guest, Not a member yet? Register   Sign In
Sending email with gmail smtp with codeigniter email library
#1

[eluser]Unknown[/eluser]
hello every1 .
This is my 1st post here.
i have almost completed my project. But i can't send a single mail with CI Sad.
please help me .
class Email extends Controller {
Code:
function Email()
{
        parent::Controller();  
            $this->load->library('email');
}

function index()
{
    $config['protocol']    = 'smtp';
    $config['smtp_host']    = 'ssl://smtp.gmail.com';
    $config['smtp_port']    = '465';
    $config['smtp_timeout'] = '7';
    $config['smtp_user']    = '[email protected]';
    $config['smtp_pass']    = '*******';
    $config['charset']    = 'utf-8';
    $config['newline']    = "\r\n";
    $config['mailtype'] = 'text'; // or html
    $config['validation'] = TRUE; // bool whether to validate email or not      

    $this->email->initialize($config);


    $this->email->from('[email protected]', 'myname');
    $this->email->to('[email protected]');

    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');  

    $this->email->send();

    echo $this->email->print_debugger();

     $this->load->view('email_view');

   }

I am getting this error A PHP Error was encountered

Severity: Warning

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

Filename: libraries/Email.php

Line Number: 1641

Using PORT 25/587 I got this error

"""A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:func(119):reason(252)

Filename: libraries/Email.php

Line Number: 1641""""

I dont want to use phpmailer now. (Actually i have tried to use phpmailer,but i falied )
#2

[eluser]dsloan[/eluser]
I had problems with this initially and got around it by loading the parameters into an array, then initialising the library using the array.

Code:
$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html',
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.
        
$result = $this->email->send();
#3

[eluser]Unknown[/eluser]
It worked!!!
Thank u very much
#4

[eluser]oste15[/eluser]
That solved the issue for me too

Does this mean using config/email.php is deprecated?

I was using $this->load->library('email');
and removing config/email.php and adding the $config array directly to the controller and using $this->load->library('email', $config); Worked
#5

[eluser]miss_amylee[/eluser]
hy bapjon,

how did u resolve the problem..actually, i did this last week and its working fine. i received d email to target email.btw, yesterday i run again d code and i got problem same as yours.. fsockopen error.. i really dun have any idea bout this error since the code are exactly same ( i used code given at first page). is dat problem with my server or else?thx for any helps guys.
#6

[eluser]miss_amylee[/eluser]
sorry, this is my code:

<?php

class Test1 extends Controller{

function __construct()
{
parent::Controller();
}

function index()
{
$data['pagetitle'] = 'Account Activation';
$email = $this->load->view('account/test1',$data,TRUE);

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '#######@gmail.com',
'smtp_pass' => '#######',
'mailtype' => 'html',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

$this->email->from('########@gmail.com', 'farah');
$this->email->to('######@yahoo.com');

$this->email->subject(' Testing testing testing....');

$this->email->message($email);

if (!$this->email->send())
show_error($this->email->print_debugger());
else
echo 'Your e-mail has been sent!';
}
}
?>
#7

[eluser]Unknown[/eluser]
I'm sorry,

may i know the solve about this problem???i made a web n i found this problem to. This is my code :

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => '[email protected]',
'smtp_pass' => 'yyyyyy',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);

$this->load->library('email',$config);
$this->email->set_newline("\r\n");

$this->email->from($emailkontak, $namakontak);
$this->email->to('[email protected]');

$this->email->subject("[".$tujuankontak."]"." ".$subjectkontak);
$this->email->message($pesankontak);

$this->email->send();

Please help me to solve this problem. Thnx for advance...
#8

[eluser]HA[/eluser]
[quote author="dsloan" date="1255907523"]I had problems with this initially and got around it by loading the parameters into an array, then initialising the library using the array.

Code:
$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html',
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.
        
$result = $this->email->send();
[/quote]

Worked great! Tks!
#9

[eluser]Unknown[/eluser]
Hi im a beginner and still a little bit stuck....

My Code

<?php

class Email extends Controller
{
function Email()
{
parent::Controller();
$this->load->library('email');
}


function index(){
// Collect data


// Config Server
$config_array = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");


$this->email->from('xxx');
$this->email->to('xxx');

$this->email->subject('Website Contact Message');


$this->email->message('Hello World');

$this->email->send();
echo $this->email->print_debugger();
}

}
?>

i am getting this response

You did not specify a SMTP hostname.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
#10

[eluser]Unknown[/eluser]
Thank you for information.




Theme © iAndrew 2016 - Forum software by © MyBB