Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

php - Send email by Email Class in codeigniter with Gmail

I want send a email by Email Class in codeigniter with gmail, but i get following error:

Error:

A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at "ssl://smtp.googlemail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553

This is my full function in controll:

function send_mail(){
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'xxxxxxx';

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

$this->email->from('[email protected]', 'Negin Phosphate Shomal');
$this->email->to('[email protected]');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');

if($this->email->send())
{
    echo 'Your email was sent, successfully.';
}

else
{
    show_error($this->email->print_debugger());
}
}

I changed SMTP in php.ini as this:

SMTP = ssl://smtp.googlemail.com
smtp_port = 25

What do i do?

With respect

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

this is what worked for me

$email_config = Array(
            'protocol'  => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => '465',
            'smtp_user' => '[email protected]',
            'smtp_pass' => 'password',
            'mailtype'  => 'html',
            'starttls'  => true,
            'newline'   => "
"
        );

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

        $this->email->from('[email protected]', 'invoice');
        $this->email->to('[email protected]');
        $this->email->subject('Invoice');
        $this->email->message('Test');

        $this->email->send();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...