我正在使用CodeIgniter版本2.2.1发送电子邮件。但它给了我错误。这是我的PHP代码:
$config = array(
'protocol'=>'smtp',
'smtp_host'=>'ssl://smtp.googlemail.com',
'smtp_port'=>465,
'smtp_user'=>'xxx@gmail.com',
'smtp_pass'=>'xxx'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('xxx@gmail.com', "My Name");
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
return $this->email->print_debugger();
但是当我发送时,它给了我这个错误。我尝试了很多方法。为什么会这样?
220 smtp.gmail.com ESMTP ci2sm13227458pbc.66 - gsmtp
hello: 250-smtp.gmail.com at your service, [61.4.76.240]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
from: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
to: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
data: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp
502 5.5.1 Unrecognized command. ci2sm13227458pbc.66 - gsmtp
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. ci2sm13227458pbc.66 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Thu, 15 Oct 2015 08:45:28 +0200
From: "War" <iljimae.ic@gmail.com>
Return-Path: <iljimae.ic@gmail.com>
To: iljimae.ic@gmail.com
Subject: =?utf-8?Q?subject?=
Reply-To: "iljimae.ic@gmail.com" <iljimae.ic@gmail.com>
X-Sender: iljimae.ic@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <561f4b884c5d7@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Every find bro ? I am here for u .
我正在使用xampp的localhost。我是否需要在本地主机中配置某些内容?
答案 0 :(得分:1)
试试这个:
public function some_name() {
$email = $this->input->post('email');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '*****@gmail.com',
'smtp_pass' => '*****',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
/*
*
* Send email with #temp_pass as a link
*
*/
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('****@gmail.com', "****");
$this->email->to($email);
$this->email->subject("***********");
$message = "<p>Your Account ************</p>";
$this->email->message($message);
$result = $this->email->send();
}
答案 1 :(得分:0)
试试这个
{{1}}
如果这项工作让我知道。 您可以稍后修改您的代码。 有关如何在codeigniter中发送电子邮件的更多信息,请尝试此链接http://w3code.in/2015/09/how-to-send-email-using-codeigniter/
答案 2 :(得分:0)
这是我目前正在使用的完全正常的电子邮件功能。
public function send_email($to, $subject, $message)
{
// Initilize email configuration
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'intsmtp.abc.com.sg',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('ABCMaster');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
return ($this->email->send()); // returns TRUE or FALSE
}
以下是我如何使用它:
$to = "abc@gmail.com";
$subject = "Learning ABCs";
$message = "ABCs are very simple. I am using them now.<br>";
$message .= "If you would like to learn more, please contact me.";
// Send email
if ( $this->send_email( $to, $subject, $message ) )
{
// Sending email success
}
else
{
// Sending Email has failed
}
答案 3 :(得分:0)
请使用以下代码段检查您的代码
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'mail.google.com',
//'smtp_port' => '465',
'smtp_timeout' => '7',
'smtp_user' => 'info@gmail.com',
'smtp_pass' => 'password',
'charset' => 'utf-8',
'newline' => "rn",
'mailtype' => 'html', // or html
'wordwrap' => FALSE,
'validation' => TRUE // bool whether to validate email or not
);
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("rn");
$this->email->from($email, 'Subject');
$this->email->to('nam@gmail.com,nam@gmail.com,nam@gmail.com');
$this->email->subject('Contact us form by: ' . $name);
$this->email->message($message . '<br>website:' . $website);
$this->email->send();
//echo $this->email->print_debugger(); `enter code here`
请使用上面的代码检查您的代码。使用// echo $this->email->print_debugger();
调试邮件代码。如果问题仍然存在,请在此处发布。
答案 4 :(得分:0)
谢谢大家的帮助。最后我得到了答案。问题来自谷歌。它阻止了安全性较低的应用。因此,我在登录谷歌后导航到此网址https://www.google.com/settings/security/lesssecureapps并打开访问不太安全的应用。你可以在那里找到更多细节。