eri*_*hak 1 php email smtp codeigniter
嘿,我正在使用Codeigniter的电子邮件助手,并解决了一个奇怪的问题.我有以下代码:
$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>";
Run Code Online (Sandbox Code Playgroud)
现在这个代码在foreach循环中,在这种情况下是两次.mpdf_create_billing返回PDF文件的路径.现在这个代码回显了2个不同的文件路径,但电子邮件是相同的,并且在两个循环运行中,两个电子邮件都包含相同的文件,尽管文件路径不同.
谁知道如何解决它?这是我的输出:
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
Run Code Online (Sandbox Code Playgroud)
这可能是我的SMTP服务器发送电子邮件的问题?我在2个邮件帐户上尝试过,结果相同.
也许你应该清除$ this-> email?
来自CodeIgniter文档:
$this->email->clear()
Run Code Online (Sandbox Code Playgroud)
将所有电子邮件变量初始化为空状态.如果您在循环中运行电子邮件发送功能,允许在循环之间重置数据,则可以使用此功能.
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();
}
Run Code Online (Sandbox Code Playgroud)
如果将参数设置为TRUE,则也会清除任何附件:
$this->email->clear(TRUE);
Run Code Online (Sandbox Code Playgroud)
在我看来这是你在做什么?
链接CI3:https://www.codeigniter.com/user_guide/libraries/email.html
链接CI2:https://www.codeigniter.com/userguide2/libraries/email.html
| 归档时间: |
|
| 查看次数: |
3412 次 |
| 最近记录: |