我在这个网站和许多其他网站上看到了同样的问题,但他们提供的解决方案对我不起作用。所以我又问了。
要发送邮件,我编写了以下代码
<?php
class Email extends CI_Controller{
function __construct()
{
parent::__construct();
}
function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'username' => 'mymail@gmail.com',
'password' => 'password'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('mymail@gmail.com', 'mymail bcc');
$this->email->to('mymail@gmail.com');
$this->email->subject('This is a test email');
$this->email->message('Oops This is Great.');
if($this->email->send())
{
echo 'Your email was sent';
}
else
{
show_error($this->email->print_debugger());
}
}
}
我安装了 openssl 并且还取消了 php.ini 中的 extension=php_openssl.dll 行的注释。但我得到以下错误
An Error Was Encountered
220 mx.google.com ESMTP qp6sm2730344pbc.55
hello: 250-mx.google.com at your service, [119.30.39.78]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250 ENHANCEDSTATUSCODES
from: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn
more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55
to: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55
The following SMTP error was encountered: 530-5.5.1 Authentication Required.
Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55
data: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1
http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55
502 5.5.1 Unrecognized command. qp6sm2730344pbc.55
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. qp6sm2730344pbc.55
Unable to send email using PHP SMTP. Your server might not be configured to send
mail using this method.
当我使用 parent::CI_Controller(); 我收到一个致命错误致命错误:在第 6 行调用 C:\wamp\www\test\application\controllers\email.php 中未定义的方法 CI_Controller::CI_Controller() 虽然我使用的是 php 5.4.3
请让我知道我在这里缺少什么。