2013-12-10 106 views
1

我試圖從我的網站的聯繫表格發送電子郵件。 我使用笨和引導,用jQuery驗證,下面的代碼:CodeIgniter不在本地主機發送電子郵件

HTML,代碼視圖名爲 「bootstrap.php中」:

   <div class="col-sm-12 contact-form" > 

        <form class="form-inline" id="validate_form" role="form" method="POST" action="index.php/site/send_email"> 
         <div class="form-group"> 
         <input type="text" class="form-control" id="form_name" name="form_name" placeholder="Name"> 
         </div> 
         <div class="form-group"> 
         <input type="email" class="form-control" id="form_email" name="form_email" placeholder="Email"> 
         </div> 
        <div class="form-group"> 
         <textarea class="form-control animated-textarea" id="form_message" name="form_message" placeholder="Message" cols="30" ></textarea> 
         </div> 
         <button type="submit" id="form_submit" class="btn btn-default">Submit</button> 
        </form> 

       </div> 

      </div> 

     </div> 

的Javascript:

$('#validate_form').validate({ 
errorElement: 'span', 
rules:{ 
    form_name:{ 
     required:true, 
     minlength:2 

    }, 
    form_email:{ 
     required:true, 
     email:true 
    }, 

    form_message:{ 
     required:true, 
     minlength:20, 
     maxlength:500 
    } 
}, 

messages:{ 
    form_name:{ 
     required:"!", 
     minlength:"!", 

    }, 
    form_email:{ 
     required:"!", 
     email:"!", 
    }, 

    form_message:{ 
     required:"!", 
     minlength: "!", 
     maxlength: "!", 
    } 

}, 



}); 

控制器:

<?php 

class Site extends CI_Controller{ 

    public function index() 
    { 
     $this->show(); 
    } 

    public function show() 
    { 
     $this->lang->load('main'); 
     $this->load->view('bootstrap'); 
    } 

    public function send_email() 
    { 

      $config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '', // have my email here 
    'smtp_pass' => '', // and my password here 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE 
); 

     $this->load->library('email', $config); 
     $name = $this->input->post('form_name', TRUE); 
     $email = $this->input->post('form_email', TRUE); 
     $message = $this->input->post('form_message', TRUE); 
     $this->email->from($email, 'Teste'); 
     $this->email->to('');//my mail here 
     $this->email->subject('Inside Visions Contact Message'); 
     $this->email->message($message); 
     $this->email->send(); 

     if ($this->email->send()){ 

      $this->load->view('bootstrap'); 
     } 
     else { 
      echo 'error'; 
     } 
    } 
} 

?> 

缺失的是什麼?它向我展示了錯誤,當它沒有錯誤時,它刷新頁面,但在我的郵箱中沒有郵件。

+2

您的**'localhost'**上是否安裝了**郵件服務器**和**'running'**? – reikyoushin

+0

爲什麼我讀,用於在localhost發送電子郵件我只需要$ config數組,我有 – user3088049

+0

你需要一個郵件服務器發送郵件..我相信你的配置假設你有一個在你的服務器上運行.. – reikyoushin

回答

0

試試這個!

function emailformat($c_id,$days){ 
      $config['protocol'] = 'smtp'; // mail, sendmail, or smtp The mail sending protocol. 
      $config['smtp_host'] = '10.10.10.10'; // SMTP Server Address. 
      $config['smtp_user'] = '[email protected]'; // SMTP Username. 
      $config['smtp_pass'] = '12345'; // SMTP Password. 
      $config['smtp_port'] = '25'; // SMTP Port. 
      $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds). 
      $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean) Enable word-wrap. 
      $config['wrapchars'] = 76; // Character count to wrap at. 
      $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work. 
      $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.). 
      $config['validate'] = FALSE; // TRUE or FALSE (boolean) Whether to validate the email address. 
      $config['priority'] = 3; // 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal. 
      $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
      $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
      $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean) Enable BCC Batch Mode. 
      $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch. 

       $this->load->library('email'); 
       $this->email->initialize($config); 
       $this->email->from('[email protected]', 'Robot'); 
       $this->email->to('[email protected]'); 
       $this->email->subject('Expiration Notification of '); 
       $this->email->message('<html><body>This Message is to notify you that contract will expire in ' !</body></html>'); 
       $this->email->send(); 
    } 
相關問題