简体   繁体   English

PHP发送响应后发送电子邮件

[英]PHP Send email after send response

I have function in my php code: 我的PHP代码中有功能:

foreach ($myarray as $customer) {
     //doing some code
     $this->sendMail($this->attachedfiles,$customer);
}

$this->response($this->success);

This code loop over array and the send email to each one with attachedfiles and response to the client in the end. 此代码循环遍历数组,并向每个电子邮件发送带有attachedfiles ,最后对客户端进行响应。

the problem with this is that it take a lot of time. 问题是这需要很多时间。 so i tried some thing like this: 所以我尝试了这样的事情:

$customer_email = array();
$customer_attachedfiles = array();

foreach ($myarray as $customer) {
     array_push($customer_email, $customer);
     array_push($customer_attachedfiles, $this->attachedfiles);
}

$this->response($this->success);

$indextmp = 0; 
foreach ($customer_email as $customer2) {
     $attachedfiles_tmp = $customer_attachedfiles($indextmp);
     $this->sendMail($attachedfiles_tmp,$customer2);
     $indextmp++;
}

And in this format the mail are not sent, Any idea what can be the problem? 并且不以这种格式发送邮件,知道是什么问题吗?

You can use Swift Mailer or PHPMailer. 您可以使用Swift Mailer或PHPMailer。 With this libraries you can easily send mails to many e-mails with one action. 使用此库,您可以通过一个动作轻松地将邮件发送到许多电子邮件。 http://swiftmailer.org/docs/introduction.html http://swiftmailer.org/docs/introduction.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM