Php 遇到错误
我正在学习一个旧的教程,面临下面给出的问题,请帮助我。 我认为这很容易,但有一些问题我无法理解 使用codeigniter发送邮件时遇到错误,错误如下:Php 遇到错误,php,Php,我正在学习一个旧的教程,面临下面给出的问题,请帮助我。 我认为这很容易,但有一些问题我无法理解 使用codeigniter发送邮件时遇到错误,错误如下: 220 mx.google.com ESMTP f4sm2807502pbg.56 hello: 250-mx.google.com at your service, [119.30.39.69] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN X
220 mx.google.com ESMTP f4sm2807502pbg.56
hello: 250-mx.google.com at your service, [119.30.39.69]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250-ENHANCEDSTATUSCODES
250 PIPELINING
from: 250 2.1.0 OK f4sm2807502pbg.56
to: 553-5.1.2 We weren't able to find the recipient domain. Please check for any
553-5.1.2 spelling errors, and make sure you didn't enter any spaces, periods,
553 5.1.2 or other punctuation after the recipient's email address. f4sm2807502pbg.56
The following SMTP error was encountered: 553-5.1.2 We weren't able to find the recipient domain. Please check for any 553-5.1.2 spelling errors, and make sure you didn't enter any spaces, periods, 553 5.1.2 or other punctuation after the recipient's email address. f4sm2807502pbg.56
data: 503 5.5.1 RCPT first. f4sm2807502pbg.56
The following SMTP error was encountered: 503 5.5.1 RCPT first. f4sm2807502pbg.56
502 5.5.1 Unrecognized command. f4sm2807502pbg.56
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. f4sm2807502pbg.56
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Wed, 11 Apr 2012 12:46:40 +0000
From: "myname"
Return-Path:
To: $email
Subject: =?utf-8?Q?This_is_an_email_test?=
Reply-To: "m.methun@gmail.com"
X-Sender: m.methun@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4f857d304b4f7@gmail.com>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B_ATC_4f857d304b520"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ATC_4f857d304b520
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Its working. Great!
--B_ATC_4f857d304b520
Content-type: text/plain; name="yourinfo.txt"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64
ZmZmZmZmZmY=
--B_ATC_4f857d304b520--
220 mx.google.com ESMTP f4sm2807502pbg.56
您好:250-mx.google.com为您服务,[119.30.39.69]
250号35882577
250-8比特
250-AUTH登录普通XOATH
250-增强状态码
250流水线
起始:250 2.1.0正常f4sm2807502pbg.56
收件人:553-5.1.2我们无法找到收件人域。请检查是否有任何问题
553-5.1.2拼写错误,并确保未输入任何空格、句点、,
553 5.1.2或收件人电子邮件地址后的其他标点符号。f4sm2807502pbg.56
遇到以下SMTP错误:553-5.1.2我们无法找到收件人域。请检查是否存在任何553-5.1.2拼写错误,并确保在收件人的电子邮件地址后未输入任何空格、句点、553 5.1.2或其他标点符号。f4sm2807502pbg.56
数据:503 5.5.1 RCPT优先。f4sm2807502pbg.56
遇到以下SMTP错误:503 5.5.1 RCPT first。f4sm2807502pbg.56
502 5.5.1无法识别的命令。f4sm2807502pbg.56
遇到以下SMTP错误:502 5.5.1无法识别的命令。f4sm2807502pbg.56
无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。
用户代理:CodeIgniter
日期:2012年4月11日星期三12:46:40+0000
发件人:“我的名字”
返回路径:
收件人:$email
主题:=?utf-8?Q?这是一个电子邮件测试=
答复:“m。methun@gmail.com"
发送人:m。methun@gmail.com
X-Mailer:CodeIgniter
X优先级:3(正常)
消息ID:
Mime版本:1.0
内容类型:多部分/混合;boundary=“B_ATC_4f857d304b520”
这是MIME格式的多部分消息。
您的电子邮件应用程序可能不支持此格式。
--B_ATC_4f857d304b520
内容类型:文本/纯文本;字符集=utf-8
内容传输编码:8比特
它起作用了。伟大的
--B_ATC_4f857d304b520
内容类型:文本/纯文本;name=“yourninfo.txt”
内容处置:附件;
内容传输编码:base64
ZMZMZMY=
--B_ATC_4f857d304b520--
我的程序如下:
220 mx.google.com ESMTP f4sm2807502pbg.56
hello: 250-mx.google.com at your service, [119.30.39.69]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250-ENHANCEDSTATUSCODES
250 PIPELINING
from: 250 2.1.0 OK f4sm2807502pbg.56
to: 553-5.1.2 We weren't able to find the recipient domain. Please check for any
553-5.1.2 spelling errors, and make sure you didn't enter any spaces, periods,
553 5.1.2 or other punctuation after the recipient's email address. f4sm2807502pbg.56
The following SMTP error was encountered: 553-5.1.2 We weren't able to find the recipient domain. Please check for any 553-5.1.2 spelling errors, and make sure you didn't enter any spaces, periods, 553 5.1.2 or other punctuation after the recipient's email address. f4sm2807502pbg.56
data: 503 5.5.1 RCPT first. f4sm2807502pbg.56
The following SMTP error was encountered: 503 5.5.1 RCPT first. f4sm2807502pbg.56
502 5.5.1 Unrecognized command. f4sm2807502pbg.56
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. f4sm2807502pbg.56
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Wed, 11 Apr 2012 12:46:40 +0000
From: "myname"
Return-Path:
To: $email
Subject: =?utf-8?Q?This_is_an_email_test?=
Reply-To: "m.methun@gmail.com"
X-Sender: m.methun@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4f857d304b4f7@gmail.com>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B_ATC_4f857d304b520"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ATC_4f857d304b520
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Its working. Great!
--B_ATC_4f857d304b520
Content-type: text/plain; name="yourinfo.txt"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64
ZmZmZmZmZmY=
--B_ATC_4f857d304b520--
email.php
<?php
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index(){
$this->load->view('newsletter');
}
function send()
{
$this->load->library('form_validation');
//field name, error message, validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
if($this->form_validation->run() == FALSE)
{ // this is from validation..that works
$this->load->view('newsletter');
}
else
{
// validation has passed. now send email
$name = $this->input->post('name');
$email = $this->input->post('email');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('m.methun@gmail.com', 'myname');
$this->email->to('$email');
$this->email->subject('This is an email test');
$this->email->message('Its working. Great!');
// attachment of file...in sending mail
$path = $this->config->item('server_root');
$file = $path . '/ci/attachments/yourinfo.txt';
$this->email->attach($file);
//end
if($this->email->send())
{
echo ' mail send ';
}
else
{
show_error($this->email->print_debugger());
}
}
}
}
?>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['protocol'] = 'smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']=465;
$config['smtp_user']='m.methun@gmail.com';
$config['smtp_pass']='methun123';
?>
newsletter.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type = "text/css">
label{ display: block; };
</style>
</head>
<body>
<div id ="newsletter_form">
<?php echo form_open('email/send'); ?>
<?php
$name_data = array(
'name'=>'name',
'id' => 'name',
'value' => set_value('name')
);
?>
<?php
//three ways of taking input..from form
?>
<p><label for = "name" > Name:</label>
<?php echo form_input($name_data); ?> </p>
<p><label for = "name" >Email Address:</label>
<input type ="text" name="email" id="email"
value = "<?php echo set_value('email'); ?>">
</p>
<p> <?php echo form_submit('submit','Submit'); ?> </p>
<?php
// end of taking inputs...
?>
<?php echo form_close(); ?>
<?php echo validation_errors('<p class ="error" >'); ?>
</div>
</body>
</html>
无标题文件
标签{显示:块;};
姓名:
电邮地址:
config/email.php
<?php
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index(){
$this->load->view('newsletter');
}
function send()
{
$this->load->library('form_validation');
//field name, error message, validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
if($this->form_validation->run() == FALSE)
{ // this is from validation..that works
$this->load->view('newsletter');
}
else
{
// validation has passed. now send email
$name = $this->input->post('name');
$email = $this->input->post('email');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('m.methun@gmail.com', 'myname');
$this->email->to('$email');
$this->email->subject('This is an email test');
$this->email->message('Its working. Great!');
// attachment of file...in sending mail
$path = $this->config->item('server_root');
$file = $path . '/ci/attachments/yourinfo.txt';
$this->email->attach($file);
//end
if($this->email->send())
{
echo ' mail send ';
}
else
{
show_error($this->email->print_debugger());
}
}
}
}
?>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['protocol'] = 'smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']=465;
$config['smtp_user']='m.methun@gmail.com';
$config['smtp_pass']='methun123';
?>
我认为问题很简单,但我无法解决。在您的send()
函数中,您有以下行:
$this->email->to('$email');
因为$email在引号中,所以它返回的是字符串$email
,而不是变量$email
的值,这是因为不能在单引号标记中调用变量
将其更改为:
$this->email->to($email);
您已向“$email”发送了一封邮件,该邮件不是有效的收件人。
尝试替换:
$this->email->to('$email');
与:
它说收件人的电子邮件不正确。你是否使用“\$eMail”作为收件人的邮件地址?你真的想尝试发布更少的代码。。。为什么不只包含您认为与您的问题相关的代码?