2012-12-19 96 views
0

我試圖在codeigniter中發送電子郵件。我首先在模型中創建了一個獨立的函數,並且它在控制器中處於核心地位,並且工作得非常好。該電子郵件是在yahoo和Gmail中發送和接收的。但是當我嘗試在另一個函數中使用相同的代碼時,我需要從數據庫中選擇電子郵件地址(收件人),它給了我一個消息,表明郵件已成功發送,但實際上並未傳遞給yahoo或gmail。可能是什麼問題呢? 它甚至不會傳送到垃圾郵件/羣發郵件。使用codeigniter發送電子郵件

工作和失敗者的代碼如下。

模型功能

function sendMail() 
{ 
    $to = "[email protected]"; 
     $subject = "My Sublect"; 
     $messagetext= "stop distubbing me and work!"; 
     $config=array(
     'protocol'=>'smtp', 
     'smtp_host'=>'mail.mydomail.co.ug', 
     'smtp_port'=>25, 
     'smtp_user'=>'[email protected]', 
     'smtp_pass'=>'mypass' 
    ); 
    $this->load->library("email",$config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from("[email protected]","Joyce"); 
    $this->email->to($to); 
    $this->email->subject($subject); 
    $this->email->message($messagetext); 
    if($this->email->send()) 
    { 
     echo "Mail send successfully!"; 
    } 
    else 
    { 
     show_error($this->email->print_debugger()); 
    } 
} 

控制器FCN

function sendmail() 
{ 
    $this->load->model('customer_model'); 
    $this->customer_model->sendMail(); 
} 

但是未能工作之一是波紋管

function customer() 
{ 
    $this->load->library('email'); 
    $this->load->database(); 
    $data = array(
       'name'=>$this->input->post('name'), 
       'contact'=>$this->input->post('contact'), 
       'entity'=>$this->input->post('entity'), 
       'sector'=>$this->input->post('sector'), 
       'inquiry'=>$this->input->post('inquiry'), 
     'nature_of_inquiry'=>$this->input->post('nature_of_inquiry'), 
      'status'=>$this->input->post('status'), 

       ); 
    $this->db->insert('customers',$data); 
    $id = $this->db->insert_id(); 
    $refno = date('d/m/Y').'-C'.str_pad($id, 4, "0", STR_PAD_LEFT); 

$this->db->query("UPDATE customers set refno = '".$refno."' WHERE id = '".$id."'"); 

$query=$this->db->query("select entity,name,status,contact from customers where id ='".$id."'"); 
foreach ($query->result() as $row) 
{ 
    $entity = $row->entity; 
    $phone = $row->contact; 
    $name = $row->name; 
    $status = $row->status; 
} 

$query1=$this->db->query("select phone, email from services where entity = '".$entity."'"); 
    foreach ($query1->result() as $row) 
{ 

    $to = $row->email; 
} 
    $sms ="Dear $name, your request/compaint has been $status"; 
    //$emailtext ="yo company has been refferenced by servicecops."; 
    //$this->sendSMS(test,$phone,$sms); 
    //$subject = "Servicecops Reminder"; 
    $config=array(
     'protocol'=>'smtp', 
     'smtp_host'=>'mail.mydomain.co.ug', 
     'smtp_port'=>25, 
     'smtp_user'=>'[email protected]', 
     'smtp_pass'=>'mypass', 
     'mailtype'=>'html' 
    ); 
    $this->load->library("email",$config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from("[email protected]","Joyce"); 
    $this->email->to($to); 
    $this->email->subject("my subject"); 
    $this->email->message("yo company has been refferenced by me"); 
    if($this->email->send()) 
    { 
     echo "Mail send successfully!"; 
     echo $to; 
    } 
    else 
    { 
     show_error($this->email->print_debugger()); 
    } 

    return $this; 
    } 
+1

您可以發佈一些代碼示例以及您收到的錯誤消息。 – PhearOfRayne

+2

是否有任何特別的原因,你沒有使用CI郵件類?我們還需要查看一些代碼,並且如果您已經檢查了發送失敗的垃圾郵件框,以查看郵件標題中是否存在問題。 –

+0

請在提問時慢慢來!提供一些代碼和你試過的東西! – Haris

回答

4

首先嚐試檢查,如果你取的從數據庫中發送電子郵件。如果是,則檢查垃圾郵件。這將解決我猜測的問題。

+0

我很好地從數據庫中獲取電子郵件,因爲我試圖打印它,它來了。第一個工作的代碼是波紋管。 – user1915536

+0

你有沒有檢查垃圾郵件或垃圾郵件?有時它會變成垃圾郵件或垃圾。 – Anwar

+0

是的,我檢查過,但根本沒有郵件。編輯並放置了代碼。 – user1915536

0

如果您使用IP地址運行URL(例如:123.117.116.27/test/email/)而不是域名,則大多數郵件會收到垃圾郵件。所以檢查垃圾郵件文件夾。

+0

垃圾郵件文件夾也沒有任何郵件。 – user1915536

+0

夥計們我發現了這個問題。我在相同的函數中定義了兩次電子郵件庫,這就是爲什麼郵件沒有到達雅虎和Gmail收件箱的原因。在功能開始的時候,我放了。 $這個 - >負載>庫( '電子郵件');這在中場。 $這個 - >負載>庫( 「電子郵件」,$配置); – user1915536

1

夥計們,我發現了這個問題。我在相同的函數中定義了兩次電子郵件庫,這就是爲什麼郵件沒有到達雅虎和Gmail收件箱的原因。在功能開始的時候,我放了。 $這個 - >負載>庫( '電子郵件');這在中場。 $這個 - >負載>庫( 「電子郵件」,$配置);

相關問題