无法使用ubuntu服务器发送谷歌邮件CodeIgniter

时间:2014-07-03 10:02:37

标签: php codeigniter ubuntu smtp gmail

我尝试使用带有codeIgniter的gmail发送电子邮件。这是我的代码:

功能sendemail($ name,$ key,$ email){

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

    $econfig['protocol'] = "smtp";
    $econfig['smtp_host'] = "ssl://smtp.googlemail.com";
    $econfig['smtp_port'] = 465;
    $econfig['smtp_user'] = "*******@gmail.com"; 
    $econfig['smtp_pass'] = "******";
    $econfig['charset'] = "utf-8";
    $econfig['mailtype'] = "html";

    $this -> email -> initialize($econfig);
    $this->email->set_newline("\r\n");

    $this -> email -> from('*********@gmail.com', 'Asoft Administration');
    $this -> email -> to($email);

    $this -> email -> subject('Subject');
    $this -> email -> message("HTML MESSAGE");

    if (!$this -> email -> send()) {
        echo $this -> email -> print_debugger();
        return false;
    } else {            
        return true;
    }
}

我的环境是ubuntu服务器。我从不使用postfix或sendmail。是否需要发送Gmail邮件?我仔细检查了用户名和密码。

尝试发送电子邮件后,我会收到此错误。

你好:250-mx.google.com为您服务,[2607:5300:100:200 :: 377] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250 ENHANCEDSTATUSCODES 250 CHUNKING

无法验证密码。错误:534-5.7.14请通过网络浏览器登录,然后重试。 534-5.7.14了解更多信息,请点击534 5.7.14

来自:530-5.5.1需要身份验证。了解更多信息 530 5.5.1

遇到以下SMTP错误:530-5.5.1需要身份验证。在530 5.5.1 - gsmtp了解更多信息 to:530-5.5.1需要验证。了解更多信息 530 5.5.1

遇到以下SMTP错误:530-5.5.1需要身份验证。在530 5.5.1了解更多信息 数据:530-5.5.1需要验证。了解更多信息 530 5.5.1

遇到以下SMTP错误:530-5.5.1需要身份验证。在530 5.5.1了解更多信息 502 5.5.1无法识别的命令。 j4sm48430630qaf.31 - gsmtp 遇到以下SMTP错误:502 5.5.1无法识别的命令。 j4sm48430630qaf.31 - gsmtp 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。

User-Agent:CodeIgniter

日期:2014年7月3日星期四11:20:14 +0200

来自:" Asoft Administration" <的 ** @ gmail.com>

退货路径:< ** @ gmail.com>

收件人: ** @ gmail.com

主题:=?utf-8?Q?Qsi_Member_confirmation_mail?=

回复:" ** @ gmail.com" <的 ** .COM>

X-Sender: ** @ gmail.com

X-Mailer:CodeIgniter

X-Priority:3(正常)

消息ID:< 53b5204ed3324@gmail.com>

Mime-Version:1.0

任何人都可以帮助我...非常感谢。

2 个答案:

答案 0 :(得分:0)

我有同样的问题,这是我的工作代码:

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'my@gmail.com',
    'smtp_pass' => 'xxx',
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);

$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('my@gmail.com', 'Niraj');
$this->email->to($email);
$this->email->subject('SOME SUBJECT');
$this->email->message('<p>Some Content</p>');
$this->email->send();

答案 1 :(得分:0)

Google想要在第一次发送时进行授权。无论您是否要通过不安全的应用启用此电子邮件,Google都会向相应的电子邮件发送消息。

相关问题