0

我正在尝试在 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;
  }
4

3 回答 3

4

首先尝试检查您是否从数据库中很好地获取电子邮件。如果是,则检查垃圾邮件。这将解决我猜的问题。

于 2012-12-19T11:09:30.437 回答
1

伙计们,我发现了这个问题。我在同一个函数中定义了两次电子邮件库,这就是为什么邮件无法到达 yahoo 和 gmail 收件箱的原因。在函数开始时,我放了。$this->load->library('email'); 这在中间。$this->load->library("email",$config);

于 2012-12-20T11:28:58.283 回答
0

如果您在使用 URL(例如:123.117.116.27/test/email/)而不是域名运行时使用 IP 地址,大多数邮件都会收到垃圾邮件。所以检查垃圾邮件文件夹。

于 2012-12-19T11:12:04.050 回答