Php 使用CodeIgniter和gmail smtp从本地主机上的xampp发送电子邮件
我正在尝试使用xampp服务器在localhost上的CodeIgniter应用程序中创建和测试电子邮件功能。我试图通过在php.ini和sendmail.ini中配置来使用Google SMTP邮件服务器。我犯了很多我无法理解的错误。我的gmail帐户使用两步身份验证。那有关系吗?这是我的密码 控制器:Php 使用CodeIgniter和gmail smtp从本地主机上的xampp发送电子邮件,php,codeigniter,email,smtp,xampp,Php,Codeigniter,Email,Smtp,Xampp,我正在尝试使用xampp服务器在localhost上的CodeIgniter应用程序中创建和测试电子邮件功能。我试图通过在php.ini和sendmail.ini中配置来使用Google SMTP邮件服务器。我犯了很多我无法理解的错误。我的gmail帐户使用两步身份验证。那有关系吗?这是我的密码 控制器: $this->load->library('email'); $from =$this->input->post('email'); $econfig= ar
$this->load->library('email');
$from =$this->input->post('email');
$econfig=
array(
'protocol'=>'smtp',
'smtp_host'=>"smtp.gmail.com",
'smtp_port'=>465,
'_smtp_auth'=>TRUE,
'smtp_user'=>"deb.pratyush@gmail",
'smtp_pass'=>"xxxxxxxx",
'smtp_crypto'=>'ssl',
'mailtype'=>'html',
'charset'=>'utf-8',
'validate'=>TRUE);
$this->email->initialize($econfig);
$this->email->set_newline("\r\n");
$msg=$this->input->post('msg');
$subject = "Contact Request From ".$from ;
$name=$this->input->post('uname');
$this->email->to("deb.pratyush@gmail.com");
$this->email->from($from, stripslashes($name));
$this->email->subject($subject);
$this->email->message($msg);
if($this->email->send())
{
$this->session->set_flashdata('msg', "Message Sent");
$url = base_url().'cms/contact-us';
redirect($url);
}
else{
echo "fail<br>";
//echo "m=".mail("deb.pratyush@gmail.com", $subject, $msg)."<br>";
echo $this->email->print_debugger();
}
SENDMAIL INI:
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=deb.pratyush@gmail.com
auth_password=xxxxxxxx
force_sender=deb.pratyush@gmail.com
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=deb.pratyush@gmail.com
auth_password=<app-specific password>
force_sender=deb.pratyush@gmail.com
错误:
fail
220 mx.google.com ESMTP jp10sm8036081pbb.9 - gsmtp
hello: 250-mx.google.com at your service, [223.239.160.146]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted.
Learn more at 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9 - gsmtp
from: 530-5.5.1 Authentication Required.
Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9 - gsmtp
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 jp10sm8036081pbb.9 - gsmtp
to: 530-5.5.1 Authentication Required.
Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9 - gsmtp
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 jp10sm8036081pbb.9 - gsmtp
data: 530-5.5.1 Authentication Required.
Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9 - gsmtp
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 jp10sm8036081pbb.9 - gsmtp
502 5.5.1 Unrecognized command. jp10sm8036081pbb.9 - gsmtp
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. jp10sm8036081pbb.9 - gsmtp
Unable to send email using PHP SMTP.
Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Sat, 2 May 2015 18:31:32 +0200
To: deb.pratyush@gmail.com
From: "John D\'Costa" <jd@mailinator.com>
Return-Path: <jd@mailinator.com>
Subject: =?utf-8?Q?Contact_Request_From_jd@mailinator.com?=
Reply-To: "jd@mailinator.com" <jd@mailinator.com>
X-Sender: jd@mailinator.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5544fbe4a6133@mailinator.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5544fbe4a6133"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_5544fbe4a6133
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
tyftyttrtv jhvyugu
--B_ALT_5544fbe4a6133
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
tyftyttrtv jhvyugu
--B_ALT_5544fbe4a6133--
失败
220 mx.google.com ESMTP jp10sm8036081pbb.9-gsmtp
您好:250-mx.google.com为您服务,[223.239.160.146]
250号35882577
250-8比特
250-AUTH登录普通XOAUTH2普通客户端令牌XOAUTH
250-增强状态码
250-流水线
250-分块
250 SMTPUTF8
无法验证密码。错误:535-5.7.8不接受用户名和密码。
在535.7.8了解更多信息http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
发件人:530-5.5.1需要身份验证。
了解更多信息,请访问
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
遇到以下SMTP错误:需要530-5.5.1身份验证。
在530 5.5.1了解更多信息http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
收件人:530-5.5.1需要身份验证。
了解更多信息,请访问
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
遇到以下SMTP错误:需要530-5.5.1身份验证。
在530 5.5.1了解更多信息http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
数据:530-5.5.1需要认证。
了解更多信息,请访问
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
遇到以下SMTP错误:需要530-5.5.1身份验证。
在530 5.5.1了解更多信息http://support.google.com/mail/bin/answer.py?answer=14257 jp10sm8036081pbb.9-gsmtp
502 5.5.1无法识别的命令。jp10sm8036081pbb.9-gsmtp
遇到以下SMTP错误:502 5.5.1无法识别的命令。jp10sm8036081pbb.9-gsmtp
无法使用PHP SMTP发送电子邮件。
您的服务器可能未配置为使用此方法发送邮件。
用户代理:CodeIgniter
日期:2015年5月2日星期六18:31:32+0200
致:黛布。pratyush@gmail.com
摘自:“约翰·德科斯塔”
返回路径:
主题:=?utf-8?Q?联系请求_jd@mailinator.com?=
答复:jd@mailinator.com"
X-Sender:jd@mailinator.com
X-Mailer:CodeIgniter
X优先级:3(正常)
消息ID:
Mime版本:1.0
内容类型:多部分/备选;boundary=“B_ALT_5544fbe4a6133”
这是MIME格式的多部分消息。
您的电子邮件应用程序可能不支持此格式。
--B_ALT_5544fbe4a6133
内容类型:文本/纯文本;字符集=utf-8
内容传输编码:8比特
TyftyTTRTTV jhvyugu
--B_ALT_5544fbe4a6133
内容类型:text/html;字符集=utf-8
内容传输编码:引用可打印
TyftyTTRTTV jhvyugu
--B_ALT_5544fbe4a6133--
我找到了解决方案。我的gmail帐户使用两步身份验证。因此,我需要创建一个特定于应用程序的密码,并用特定于应用程序的密码替换我以前的密码,以便通过PHP完全访问我的gmail帐户。
我在sendmail.exe的错误日志中找到了下面给出的链接
它详细介绍了如何创建特定于应用程序的密码
代码如下:
$econfig=
array(
'protocol'=>'smtp',
'smtp_host'=>"smtp.gmail.com",
'smtp_port'=>465,
'_smtp_auth'=>TRUE,
'smtp_user'=>"deb.pratyush@gmail",
'smtp_pass'=>"<app-specific password>",
'smtp_crypto'=>'ssl',
'mailtype'=>'html',
'charset'=>'utf-8',
'validate'=>TRUE);
$econfig=
排列(
“协议”=>“smtp”,
“smtp_主机”=>“smtp.gmail.com”,
“smtp_端口”=>465,
“\u smtp\u auth”=>正确,
“smtp_用户”=>“deb。pratyush@gmail",
“smtp_pass”=>“”,
'smtp_crypto'=>'ssl',
'mailtype'=>'html',
“字符集”=>“utf-8”,
“验证”=>TRUE);
SENDMAIL INI:
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=deb.pratyush@gmail.com
auth_password=xxxxxxxx
force_sender=deb.pratyush@gmail.com
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=deb.pratyush@gmail.com
auth_password=<app-specific password>
force_sender=deb.pratyush@gmail.com
smtp_server=smtp.gmail.com
smtp_端口=465
smtp_ssl=auto
error\u logfile=error.log
debug_logfile=debug.log
auth_username=deb。pratyush@gmail.com
验证密码=
force_sender=deb。pratyush@gmail.com
这让我走上了正确的道路。但是,
我所要做的就是打开“允许不太安全的应用程序访问你的帐户”。我想这是创建特定于应用程序的密码的替代方法
供参考
开关
为了安全起见,在完成后将其关闭可能是值得的。看看这个
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'xyz.com';
$config['smtp_port'] = '25';
$config['smtp_timeout'] = '100';
$config['smtp_user'] = 'aaa@xyz.com';
$config['smtp_pass'] = '*******';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or text
$config['validation'] = TRUE;
$this->email->initialize($config);
//$this->email->set_newline("\r\n");
$this->email->from('aaa@xyz.com', 'TESTING');
$this->email->to('abc@gmail.com');
$this->email->subject('Email Test');
$body = read_file(base_url().'resources/img/index.html');
$this->email->message($body);
if($this->email->send())
{
echo $this->email->print_debugger(); echo 'mail send'.$body;
}
else
echo $this->email->print_debugger();
but not recive any mail