我正在使用CodeIgniter及其默认库。每当我发送电子邮件时,它都会发送两次。有没有人有一些调试指针或提示来解决这个问题?
$this->CI->email->from($this->from, $this->company_name);
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);
eval("\$message = \"".$this->message."\";");
$this->CI->email->message($this->message);
if($attachment != "")
{
$attac_exp=explode(",",$attachment);
foreach($attac_exp as $key=>$value)
{
if($value != '')
{
$this->CI->email->attach(getcwd()."/attachments/".$value);
}
}
}
$this->CI->email->send();
$this->CI->email->clear(true);
我现在已经使用SMTP配置了sendmail。
如果我尝试通过命令行发送电子邮件,我只收到一封电子邮件。据我所知,问题必须与CodeIgniter有关。我已经对此进行了研究。
答案 0 :(得分:0)
以下是与电子邮件中附加单个文件完美配合的示例代码段。请相应参考和纠正。
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$dummyfrom='admin@mydoamin.com';
$system_name = "Test Company";
$from = 'rajesh@abcd.com';
$to ='to@abcd.com';
$bcc = 'bcc@abcd.com';$sub="Attachment Test";
$msg = "Please ignore this mail";
$this->load->library('email');
$this->email->initialize($config);
$this->email->from($dummyfrom, $system_name);
$this->email->reply_to($from);
$this->email->to($to);
$this->email->bcc($bcc);
$this->email->subject($sub);
$this->email->message($msg);
$this->email->attach(APPPATH.'test.txt');
$this->email->send();
请注意,它会从应用路径中选择文件test.txt
。
您可以使用$this->email->print_debugger()
查看调试。