2013-03-12 175 views
1

我有一個「聯繫我們」頁面,如果用戶提交表單。然後電子郵件應該去指定的電子郵件。Codeigniter:無法發送電子郵件

提交表單後,我收到了成功消息,但在收件箱/垃圾郵件中沒有看到任何電子郵件。

我正在測試我的活服務器

Pelase幫我解決了我的問題。

我的代碼:

<?php 
     if (! defined('BASEPATH')) exit('No direct script access allowed'); 

     class contact extends CI_Controller { 
      public function __construct() 
      { 
       parent:: __construct(); 
       $this->load->helper('url'); 
       $this->load->helper('form'); 
       $this->load->library('session'); 
       $this->load->library('email'); 
       $this->load->model('shopmodel'); 
       $this->load->model('contactusmodel'); 
       $this->load->library('form_validation'); 
      } 

      function index() 
      { 
       $this->form_validation->set_error_delimiters(' <li class="errorlist">', '</li>')->set_rules('fullname', 'Name','trim|required|min_length[5]|max_length[50]|xss_clean'); 
       $this->form_validation->set_error_delimiters('<li class="errorlist">', '</li>')->set_rules('countryname', 'Country','trim|required|min_length[2]|max_length[50]|xss_clean'); 
       $this->form_validation->set_error_delimiters('<li class="errorlist">', '</li>')->set_rules('email', 'Email', 'trim|required|valid_email'); 
       $this->form_validation->set_error_delimiters('<li class="errorlist">', '</li>')->set_rules('contactdetails', 'Contact Details','trim|required|min_length[40]|max_length[2000]|xss_clean'); 
       $data=$this->contactusmodel->contactusmodel(); 
       $data["query"] = $this->shopmodel->getshopdetailsById(199);//taking data as shop id 199 

        if($this->form_validation->run() === FALSE) 
        { 
         $data['ffullname']['value'] = $this->input->post('fullname'); 
         $data['fcountryname']['value'] =$this->input->post('email'); 
         $data['femail']['value'] = $this->input->post('countryname'); 
         $data['fcontactdetails']['value'] =$this->input->post('contactdetails'); 
         $this->load->view('contact/contact',$data); 
        } 

        else if ($this->form_validation->run() === TRUE) 
        { 
         $name=$this->input->post('fullname'); 
         $sendersemail=$this->input->post('email'); 
         $fromcountry=$this->input->post('countryname'); 
         $message=$this->input->post('contactdetails'); 

         $config = Array(
         'protocol' => 'smtp', 
           'smtp_host' => 'ssl://smtp.googlemail.com', 
           'smtp_port' => 465, 
           'smtp_user' => '[email protected]', 
           'smtp_pass' => 'xxxxxxxx', 
           'mailtype' => 'html', 
           'charset' => 'utf-8', 
           'wordwrap' => TRUE 

        ); 

         $this->load->library('email', $config); 
         $this->email->set_mailtype("html"); 
         $this->email->set_newline("\r\n"); 
         $email_body ="<div>hello world</div>"; 
         $this->email->from('[email protected]', 'ddd'); 

         $list = array('[email protected]'); 
         $this->email->to($list); 
         $this->email->subject('Testing Email'); 
         $this->email->message($email_body); 

         $this->email->send(); 
         echo $this->email->print_debugger(); 
        } 
        else{ 
         $this->load->view('contact/contact',$data); 
        } 
      } 
     } 
     ?> 

什麼輸出我得到的是:

[code] 
    Your message has been successfully sent using the following protocol: mail 
    From: "ddd" 
    Return-Path: 
    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/alternative; boundary="B_ALT_513e1456185e3" 


    =?utf-8?Q?Testing_Email?= 
    This is a multi-part message in MIME format. 
    Your email application may not support this format. 

    --B_ALT_513e1456185e3 
    Content-Type: text/plain; charset=utf-8 
    Content-Transfer-Encoding: 8bit 

    hello world 


    --B_ALT_513e1456185e3 
    Content-Type: text/html; charset=utf-8 
    Content-Transfer-Encoding: quoted-printable 

    <div>hello world</div> 

    --B_ALT_513e1456185e3-- 
+0

這裏的一切對我來說都很好。問題可能在其他地方。無論是不正確的電子郵件地址,還是服務器可能在發送電子郵件時遇到問題。檢查你的服務器日誌是否有錯誤我希望這不是你真正的SMTP密碼。 – 2013-03-12 05:53:02

+0

@NicholasPickering我在我的應用程序中提到的電子郵件和密碼是100%正確的。但是我不知道爲什麼郵件在上面顯示的成功信息之後沒有發送。否則有沒有其他方式發送codeigniter郵件?我也會嘗試。請幫忙 – 2013-03-12 06:00:36

+0

你可以顯示你的config/email.php嗎? – Girish 2013-03-12 06:46:41

回答

0

也許你正在試驗一箇中繼錯誤somtimes的谷歌服務器不接受郵件中繼形成一個MTA到另一個收件箱。嘗試測試以建立到您的服務器的SMTP對話框,嘗試發送郵件。下面是一個簡單的SMTP對話框例如:

http://www.soi.wide.ad.jp/class/20000009/slides/11/6.html

嘗試,如果服務器發送一個繼電器的錯誤,你應該與其他SMTP服務器嘗試發送郵件。如果不是可能是你的php的配置錯誤。

但根據我的經驗,如果MTA不是可信代理,gmail總是會拒絕中繼郵件,以防止垃圾郵件和安全問題。

另一個原因可能是您沒有正確配置DNS服務器,並且您的MTA找不到MX記錄。例如你的MTA是sendmail,它會通知php該郵件已成功發送,但如果你查看sendmail日誌,你會發現主機無法訪問。