我在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'] = "myemail@smsgt.com";
$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('noreply@smsgt.com', '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";
}
}
当我在MESSAGE中发送带有纯文本的电子邮件时,它工作正常。但问题是当我发送带有HTML脚本的电子邮件时,它不会产生错误,但它不会发送给用户,并且不会使用MS OUTLOOK收到电子邮件。有人可以帮我解决这个问题吗?谢谢你们!
答案 0 :(得分:0)
尝试添加此内容:
$this->email->priority(3);
您可以在此处找到更多信息:http://ellislab.com/codeigniter/user-guide/libraries/email.html
答案 1 :(得分:0)
您尚未使用已设置的配置值初始化电子邮件库。
您只需在代码中添加以下行。
$this->email->initialize($config);
答案 2 :(得分: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('noreply@smsgt.com', '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";
}
}
答案 3 :(得分: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'] = "myemail@smsgt.com";
$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('noreply@smsgt.com', '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();
返回“您的邮件已成功使用以下协议发送”,它只是意味着您的脚本中没有语法错误。就像我说的,我的想法是邮件服务器问题。
如果我建议这将是我将如何调试您的问题:
$C11
替换为$ci->email->to($C11);
中的Gmail地址,然后运行我当前的脚本,看看延迟问题是否相同。但无论如何,我猜你最终还是会在你的邮件服务器上挖掘一些东西( @smsgt.com )。如果我是你,我会联系你的服务器管理员并开始在邮件服务器日志中寻找线索。
答案 4 :(得分:0)
使用类似的东西
$this->load->library('email', array(
'protocol' => 'mail',
'smtp_host' => 'ssl://mail.smsgt.com',
'smtp_port' => '25',
'smtp_user' => 'myemail@smsgt.com',
'smtp_pass' => '',
'newline' => '\r\n',
'crlf' => '\r\n',
'mailtype' => 'html'
));
$this->email->to($C11);
$this->email->from('noreply@smsgt.com', 'company email');
$this->email->subject('Accountability for'. " ". $C12);
$this->email->message("testing");
if( $this->email->send() ) {
return TRUE;
} else {
return FALSE;
}
答案 5 :(得分: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'] = 'test@yahoo.com.ph'; // 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('test@yahoo.com.ph', 'Robot');
$this->email->to('test@yahoo.com.ph');
$this->email->subject('Expiration Notification');
$this->email->message('<html><body>This Message is to notify!</body></html>');
$this->email->send();
}