2017-07-27 112 views
0

我尝试Codeigniter电子邮件类,但它不工作或可能是,我犯了配置或其他的错误。请修复它,并告诉我有人应该做什么。我遇到了codeigniter电子邮件类的问题。Codeigniter电子邮件类不工作

这是将表格数据发送到控制器后的屏幕截图。

This is the screenshot after sending the form data to the controller

查看:

   <h4>Send Your Feedback</h4> 
       <form action="<?php echo base_url('front/feedBack') ?>" enctype="multipart/form-data" method="post" class="form-horizontal"> 
        <div class="form-group"> 
         <label for="Name" class="col-sm-3 control-label">Name<span>*</span></label> 
         <div class="col-sm-9"> 
          <input type="text" name="senderName" class="form-control" id="Name" placeholder="Name"> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label for="Phone" class="col-sm-3 control-label">Phone no<span>*</span></label> 
         <div class="col-sm-9"> 
          <input type="text" name="senderPhone" class="form-control" id="Phone" placeholder="Phone no"> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label for="Email" class="col-sm-3 control-label">Email<span>*</span></label> 
         <div class="col-sm-9"> 
          <input type="text" name="senderEmail" class="form-control" id="Email" placeholder="Email"> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label for="Subject" class="col-sm-3 control-label">Subject</label> 
         <div class="col-sm-9"> 
          <input type="text" name="senderSubject" class="form-control" id="Subject" placeholder="Subject"> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label for="Message" class="col-sm-3 control-label">Message<span>*</span></label> 
         <div class="col-sm-9"> 
          <textarea name="senderMsg" class="form-control" id="Message" cols="30" rows="5" placeholder="Message"></textarea> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label for="inputPassword" class="col-sm-3 control-label"></label> 
         <div class="col-sm-9"> 
          <button type="submit" class="btn btn-default btn-lg btn-block">Send Message</button> 
         </div> 
        </div> 
       </form> 

控制器:

public function feedBack() 
{ 
    $this->load->library('email'); 

    $config['protocol'] = 'smtp'; 

    $config['smtp_host'] = 'host8.registrar-servers.com'; 

    $config['smtp_port'] = '465'; 

    $config['smtp_timeout'] = '30'; 

    $config['smtp_user'] = '[email protected]'; 

    $config['smtp_pass'] = 'myPass'; 

    $config['charset'] = 'utf-8'; 

    $config['crlf'] = '\r\n';  //should be "\r\n" 
    $config['newline'] = '\r\n'; //should be "\r\n" 

    $config['mailtype'] = 'html'; // or html 

    $config['validation'] = TRUE; // bool whether to validate email or not 

    $this->email->initialize($config); 



    $senderName = $this->input->post('senderName'); 
    $senderPhone = $this->input->post('senderPhone'); 
    $senderEmail = $this->input->post('senderEmail'); 
    $senderSubject = $this->input->post('senderSubject'); 
    $senderMsg = $this->input->post('senderMsg'); 

    $this->email->from($senderEmail, $senderName); 
    $this->email->to('[email protected]'); 


    $this->email->subject($senderSubject); 

    $this->email->message($senderMsg); 

    if($this->email->send()) { 
     echo "Success!"; 
     //return true; 
    } else { 
     echo "Failure!"; 
     //return false; 
    } 

} 

回答

0

试试这个:

$config = Array(
       'protocol' => 'smtp', 
       'smtp_host' => '[email protected]', 
       'smtp_port' => 2525, 
       'smtp_user' => 'gmailusername', 
       'smtp_pass' => 'password', 
       'mailtype' => 'html', 
       'charset' => 'iso-8859-1' 
      ); 
    $config['wordwrap'] = TRUE; 
    $config['mailtype'] = 'html'; 

    $THIS->email->initialize($config); 
    $THIS->email->set_newline("\r\n"); 
    $body = str_replace(array('{LOGO_IMAGE}'),array($logo_image),$body); 

    $body.= email_footer(); 
    $body = '<div style="width:700px;float:left;">'.$body.'</div>'; 
    if (!empty($from)) 
    { 
     $from_name = !empty($from_name) ? $from_name : SITE_NAME; 
     $from = !empty($from) ? $from : '[email protected]';   
     $THIS->email->from($from, $from_name); 
    } 
    else 
    { 
     $THIS->email->from('[email protected]', $from_name); 
    } 
    if (!empty($to)) 
    { 
     $THIS->email->to($to); 
    } 
    if (!empty($cc)) 
    { 
     $THIS->email->cc($cc); 
    } 
    if (!empty($bcc)) 
    { 
     $THIS->email->cc($bcc); 
    } 
    $THIS->email->subject($subject); 
    $THIS->email->message($body); 

    if (!empty($attachment)) 
    { 
     if (is_array($attachment)) 
     { 
      foreach ($attachment as $val) 
      { 
       $THIS->email->attach($val); 
      } 
     } 
     else 
     { 
      $THIS->email->attach($val); 
     } 
    } 

    if ($THIS->email->send()) 
    { 
     return TRUE; 
    } 
    else{ 
     echo $THIS->email->print_debugger(); 
     exit; 
    } 

马克它接受它是否工作。