我试图在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;
}
您可以发布一些代码示例以及您收到的错误消息。 – PhearOfRayne
是否有任何特别的原因,你没有使用CI邮件类?我们还需要查看一些代码,并且如果您已经检查了发送失败的垃圾邮件框,以查看邮件标题中是否存在问题。 –
请在提问时慢慢来!提供一些代码和你试过的东西! – Haris