遇到了错误

时间:2012-04-11 13:21:08

标签: 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 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());
     }
   }

  }
 }
 ?>      

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>

配置/ email.php

<?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';

?>

我认为问题很简单,但我无法修复它。

2 个答案:

答案 0 :(得分:1)

send()函数中,您有以下这一行:

$this->email->to('$email');

因为$ email在引号中,它返回字符串$email而不是变量$email的值,这是因为你不能在单引号标签中调用变量。

将其更改为:

$this->email->to($email);

答案 1 :(得分:1)

您已向&#34; $ email&#34;发送邮件,该邮件不是有效收件人。 尝试更换:

$this->email->to('$email');

使用:

$this->email->to($email);
相关问题