php – 使用Gmail在codeigniter中通过电子邮件类发送电子邮件

我想通过电子邮件类在codeigniter中使用gmail发送电子邮件,但是我收到以下错误:

错误:

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

这是我在controll中的全部功能:

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

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

$this->email->from('neginph@gmail.com', 'Negin Phosphate Shomal');
$this->email->to('neginfos@yahoo.com');
$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());
}
}

我在php.ini中更改了SMTP,如下所示:

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

我该怎么办?

尊重地

最佳答案
这对我有用

$email_config = Array(
            'protocol'  => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => '465',
            'smtp_user' => 'someuser@gmail.com',
            'smtp_pass' => 'password',
            'mailtype'  => 'html',
            'starttls'  => true,
            'newline'   => "\r\n"
        );

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

        $this->email->from('someuser@gmail.com', 'invoice');
        $this->email->to('test@test.com');
        $this->email->subject('Invoice');
        $this->email->message('Test');

        $this->email->send();

转载注明原文:php – 使用Gmail在codeigniter中通过电子邮件类发送电子邮件 - 代码日志