本文介绍了电子邮件循环在Codeigniter中使用Email类发送相同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在使用Codeigniter的电子邮件助手,并且终止一个更严重的问题。我有以下代码:

  $ path = mpdf_create_billing($ html); 
$ this-> load-> library('email');
$ this-> email-> set_newline(\r\\\
);
$ this-> email-> from('no-reply@foo.com');
$ this-> email->至(foo@gmail.com);
$ this-> email-> subject('Invoice for'.date('d / m / y'));
$ this-> email-> message($ message);
$ this-> email-> attach($ path);
if($ this-> email-> send())
echo电子邮件已成功发送到$ email与文件$ path< br>;
else
echo应该发送电子邮件到$ email,但我没有< br>;

现在这段代码在foreach循环中,在这种情况下是两次。 mpdf_create_billing 返回到PDF文件的路径。现在这个代码回放了两个不同的文件路径,但电子邮件是相同的,并且在这两个循环运行中,两个电子邮件都包含相同的文件,尽管文件路径是不同的。



 电子邮件成功发送到foo@foo.com与文件
/ path / to / pdf / Invoice_1368452801.82065190eec1c85eb.pdf

电子邮件成功发送到foo@foo.com,文件为
/path/to/pdf/Invoice_1368452804.53475190eec482917.pdf

这可能是发送电子邮件的SMTP服务器的问题吗?我尝试使用2个邮件帐户,结果相同。

解决方案

也许您应该清除$ this-> email? >

从CodeIgniter文档:

  $ this-> email-> clear()





  foreach($ list as $ name => $ address)
{
$ this-> email-> clear() ;

$ this-> email->到($ address); $(b $ b $ this-> email-> from('your@example.com');
$ this-> email-> subject('这是你的信息'$ name);
$ this-> email-> message('嗨'。$ name。'这是你要求的信息。
$ this-> email-> send();
}





  $ this-> email-> ;清除(TRUE); 

看看我这是你在做什么?



链接:


Hey I'm using Codeigniter's Email helpers, and expiriencing a wierd issue. I have the following code :

        $path = mpdf_create_billing($html);
        $this->load->library('email');
        $this->email->set_newline("\r\n");
        $this->email->from('no-reply@foo.com');
        $this->email->to("foo@gmail.com");
        $this->email->subject('Invoice for  '.date('d/m/y'));
        $this->email->message($message);
        $this->email->attach($path);
        if($this->email->send())
            echo "Email Sent Successfully to $email with the file $path<br>";
        else
            echo "Should be sending email to $email , but i didn't<br>";

Now this code is inside a foreach loop,twice in this case. mpdf_create_billing returns path to a PDF file. now this code echos 2 different file paths, but the email is the same and in both loop runs and both of the emails contain the same file, though the file paths are different.

Anyone knows how to resolve it? this is what outputs for me :

Email Sent Successfully to foo@foo.com with the file
   /path/to/pdf/Invoice_1368452801.82065190eec1c85eb.pdf

Email Sent Successfully to foo@foo.com with the file 
  /path/to/pdf/Invoice_1368452804.53475190eec482917.pdf

Could this be a problem with my SMTP server that send the emails? I tried it on 2 mail accounts, and same result.

解决方案

Perhaps you should clear $this->email?

From the CodeIgniter docs:

$this->email->clear()
foreach ($list as $name => $address)
{
    $this->email->clear();

    $this->email->to($address);
    $this->email->from('your@example.com');
    $this->email->subject('Here is your info '.$name);
    $this->email->message('Hi '.$name.' Here is the info you requested.');
    $this->email->send();
}
$this->email->clear(TRUE);

Looks to me this is what you are doing?

Link: http://ellislab.com/codeigniter/user-guide/libraries/email.html

这篇关于电子邮件循环在Codeigniter中使用Email类发送相同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 06:19