2012-04-11 135 views
-4

我正在學習一個老的教程,面臨下面給出的問題,請幫助我。 我認爲這很容易,但有一些我無法理解的問題。遇到了一個錯誤

同時使用笨發送郵件面對錯誤,下面給出錯誤:

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: "[email protected]" 
    X-Sender: [email protected] 
    X-Mailer: CodeIgniter 
    X-Priority: 3 (Normal) 
    Message-ID: <[email protected]> 
    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('[email protected]', '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

<!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']='[email protected]'; 
$config['smtp_pass']='methun123'; 

?> 

我認爲這個問題很簡單,但我無法修復它。

+1

上面寫着收件人電子郵件是不正確的 – Dion 2012-04-11 13:23:32

+2

你真的想嘗試張貼更少的代碼......爲什麼不僅包括你覺得是相關的代碼你的問題? – Lix 2012-04-11 13:27:26

+0

你使用「\ $ email」作爲收件人的郵件地址嗎? – 2012-04-11 13:25:30

回答

1

在你send()功能你有這樣一行:

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

因爲$ email是在引號它返回字符串$email而不是變量$email的價值,這是becasue你不能叫內單變量報價標籤。

它改成這樣:

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

您發送郵件到「$電子郵件」,這是不是有效的收件人。 嘗試更換:

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

有:

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