[英]sending email using codeigniter
我正在嘗試通過codeigniter發送電子郵件。 我首先在模型中創建了一個獨立的函數,它是控制器的核心響應者,並且運行良好。 該電子郵件已通過yahoo和gmail發送和接收。 但是,當我嘗試在從數據庫中選擇電子郵件地址(收件人)的另一個函數中使用相同的代碼時,它給我一條消息,表明電子郵件已成功發送,但實際上並未傳遞給yahoo或gmail。 可能是什么問題呢? 它甚至沒有發送到垃圾郵件/大量郵件中。
下面是工作正常和失敗的代碼。
模型函數是
function sendMail()
{
$to = "mymail@yahoo.com";
$subject = "My Sublect";
$messagetext= "stop distubbing me and work!";
$config=array(
'protocol'=>'smtp',
'smtp_host'=>'mail.mydomail.co.ug',
'smtp_port'=>25,
'smtp_user'=>'myname@mydomail.co.ug',
'smtp_pass'=>'mypass'
);
$this->load->library("email",$config);
$this->email->set_newline("\r\n");
$this->email->from("myname@mydomail.co.ug","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'=>'myname@mydomain.co.ug',
'smtp_pass'=>'mypass',
'mailtype'=>'html'
);
$this->load->library("email",$config);
$this->email->set_newline("\r\n");
$this->email->from("myname@mydomain.co.ug","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;
}
首先嘗試檢查您是否從數據庫中很好地獲取了電子郵件。 如果是,則檢查垃圾郵件。 我猜那可以解決問題。
伙計們,我發現了問題。 我在同一功能中兩次定義了電子郵件庫,這就是為什么郵件無法到達yahoo和gmail收件箱的原因。 在功能開始時,我已經提出了。 $這個 - >負載>庫( '電子郵件'); 這在中部。 $這個 - >負載>庫( “電子郵件”,$配置);
如果您使用IP地址(而不是域名)運行URL(例如123.117.116.27/test/email/),則大多數郵件都會收到垃圾郵件。 因此,請檢查垃圾郵件文件夾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.