2014-01-29 580 views
0

我在发送codeigniter电子邮件时遇到问题。无法正确发送电子邮件在codeigniter

$ci = get_instance(); 
$ci->load->library('email'); 
$config['protocol'] = "mail"; 
$config['smtp_host'] = "ssl://mail.smsgt.com"; 
$config['smtp_port'] = "25"; 
$config['smtp_user'] = "[email protected]"; 
$config['smtp_pass'] = ""; 
$config['charset'] = "utf-8"; 
$config['mailtype'] = "html"; 
$config['newline'] = "\r\n"; 
$config['crlf'] = "\r\n"; 

,这里是我的代码发送电子邮件时

public function send_email_accountability($C11,$C12) 
{ 

    date_default_timezone_set('Asia/Manila'); 
    $this->load->library('email'); 
    $this->email->set_mailtype("html"); 
    $this->email->from('[email protected]', 'company email'); 
    $this->email->to($C11); 
    $this->email->subject('Accountability for'. " ". $C12); 
    $this->email->message("testing"); 

    $check = $this->email->send(); 
    //echo $this->email->print_debugger(); 
    if ($check){ 
       $data = "true"; 
    } 
      else{ 
       $data = "false"; 
      } 

} 

当我在消息发送电子邮件,纯文本,它工作正常。但问题是当我用HTML脚本发送电子邮件时,它不会产生错误,但它不会发送给用户,并且不会使用MS OUTLOOK接收电子邮件。有人可以帮我解决这个问题吗?多谢你们 !

+1

试图打印)的使用功能的var_dump的参数(使用 –

回答

0

这将有助于如果你能提供由echo $this->email->print_debugger();返回的可能的错误,所以为什么不启用它的那一刻,然后运行当前的代码。

另外,试试这个:

public function send_email_accountability($C11,$C12) 
{ 
    date_default_timezone_set('Asia/Manila'); 

    $ci =& get_instance(); 
    $ci->load->library('email'); 

    $config['protocol'] = "mail"; 
    $config['smtp_host'] = "ssl://mail.smsgt.com"; 
    $config['smtp_port'] = "25"; 
    $config['smtp_user'] = "[email protected]"; 
    $config['smtp_pass'] = ""; 
    $config['charset'] = "utf-8"; 
    $config['mailtype'] = "html"; 
    $config['newline'] = "\r\n"; 
    $config['crlf'] = "\r\n"; 

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

    $ci->email->from('[email protected]', 'company email'); 
    $ci->email->to($C11); 
    $ci->email->subject('Accountability for'. " ". $C12); 
    $ci->email->message("testing"); 

    $check = $ci->email->send(); 

    //echo $ci->email->print_debugger(); 

    if ($check) 
    $data = "true"; 
    else 
    $data = "false";  
} 

编辑

既然你在评论提到echo $ci->email->print_debugger();回报“邮件已经发送成功采用以下方案”它只是简单的手段脚本中没有语法错误。就像我说的,我的想法是邮件服务器问题。

如果我会建议这将是我将如何调试您的问题:

  • 我会在$ci->email->to($C11);使用Gmail地址替换$C11然后运行我当前的脚本,看看是否延迟的问题是相同。
  • 将您当前的SMTP服务器凭证替换为类似Mandrill的凭证,以确保其报告日志肯定会为您提供正在发生的事情提示。

但无论哪种方式,我想你还是会最终在邮件服务器上挖东西(@ smsgt.com)。如果我是你,我会联系你的服务器管理员,并开始在邮件服务器日志中寻找线索。

+0

你的邮件已成功发送使用以下协议:邮件,这是我得到的消息。我的问题现在很慢被用户接收。这个的任何细节? – Vincent

+1

$ ci =&get_instance();有没有&符号获取实例? – Vincent

+1

是的,就是'&'。我的想法是邮件服务器问题。您是否尝试通过**@smsgt.com**以外的其他电子邮件发送它? – dqlopez

0

您还没有与已设置的配置值初始化电子邮件库。

你只需要在你的代码中添加下面的行。

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

我忘了包括$ this-> email-> initialize($ config);我的问题现在很慢被用户接收。这个的任何细节? – Vincent

+0

@vincent你能否简单解释一下你的问题? –

+0

@Shenal S我的问题是,当我包含一个图像发送。该邮件根本不会发送。但是当我不包括电子邮件。我的电子邮件将被发送。并且通常需要2-5分钟才能发送 – Vincent

0
public function send_email_accountability($C11,$C12) 
{ 

    date_default_timezone_set('Asia/Manila'); 
    $this->load->library('email'); 
    $config['protocol'] = 'sendmail'; 
    $config['mailpath'] = '/usr/sbin/sendmail'; 
    $config['charset'] = 'utf-8'; 
    $config['wordwrap'] = TRUE; 
    $config['mailtype'] = 'html'; 
    $this->email->initialize($config); 
    //$this->email->set_mailtype("html"); 
    $this->email->from('[email protected]', 'company email'); 
    $this->email->to($C11); 
    $this->email->subject('Accountability for'. " ". $C12); 
    $this->email->message("testing"); 

    $check = $this->email->send(); 
    //echo $this->email->print_debugger(); 
    if ($check){ 
       $data = "true"; 
    } 
      else{ 
       $data = "false"; 
      } 

} 
0

使用这样的

$this->load->library('email', array(
        'protocol' => 'mail', 
        'smtp_host' => 'ssl://mail.smsgt.com', 
        'smtp_port' => '25', 
        'smtp_user' => '[email protected]', 
        'smtp_pass' => '', 
        'newline' => '\r\n', 
        'crlf' => '\r\n', 
        'mailtype' => 'html' 
     )); 

    $this->email->to($C11); 
    $this->email->from('[email protected]', 'company email'); 
    $this->email->subject('Accountability for'. " ". $C12); 
    $this->email->message("testing"); 

    if($this->email->send()) { 
     return TRUE; 
    } else { 
     return FALSE; 
    } 
+1

我的问题是现在它慢,被用户接收。这个的任何细节? – Vincent

0

在这里尝试这个代码是我的代码我在发送电子邮件

function emailformat(){ 
      $config['protocol'] = 'smtp'; // mail, sendmail, or smtp The mail sending protocol. 
      $config['smtp_host'] = 'smtp.gmail.com'; // SMTP Server Address. 
      $config['smtp_user'] = '[email protected]'; // SMTP Username. 
      $config['smtp_pass'] = '@password'; // SMTP Password. 
      $config['smtp_port'] = '25'; // SMTP Port. 
      $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds). 
      $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean) Enable word-wrap. 
      $config['wrapchars'] = 76; // Character count to wrap at. 
      $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work. 
      $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.). 
      $config['validate'] = FALSE; // TRUE or FALSE (boolean) Whether to validate the email address. 
      $config['priority'] = 3; // 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal. 
      $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
      $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
      $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean) Enable BCC Batch Mode. 
      $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch. 

       $this->load->library('email'); 
       $this->email->initialize($config); 
       $this->email->from('[email protected]', 'Robot'); 
       $this->email->to('[email protected]'); 
       $this->email->subject('Expiration Notification'); 
       $this->email->message('<html><body>This Message is to notify!</body></html>'); 
       $this->email->send(); 
    } 
相关问题