使用 Gmail 在 codeigniter 中通过电子邮件类发送电子邮件 [英] Send email by Email Class in codeigniter with Gmail

查看:45
本文介绍了使用 Gmail 在 codeigniter 中通过电子邮件类发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

错误:

遇到 PHP 错误
严重性:警告
消息:mail() [function.mail]: 无法连接到邮件服务器ssl://smtp.googlemail.com"端口 25,验证您的SMTP"和php.ini 中的smtp_port"设置或使用 ini_set()
文件名:library/Email.php
行号:1553

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'] = 'xyz@gmail.com';
$config['smtp_pass'] = 'xxxxxxx';

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

$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 更改为:

I changed SMTP in php.ini as this:

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

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'   => "
"
        );

        $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();

这篇关于使用 Gmail 在 codeigniter 中通过电子邮件类发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆