PHP发送响应后发送电子邮件
我的php代码中有一个函数:PHP发送响应后发送电子邮件,php,html,Php,Html,我的php代码中有一个函数: foreach ($myarray as $customer) { //doing some code $this->sendMail($this->attachedfiles,$customer); } $this->response($this->success); 此代码循环数组,并使用attachedfiles向每个人发送电子邮件,最后向客户端做出响应 问题是这需要很多时间。所以我试过这样的方法: $custo
foreach ($myarray as $customer) {
//doing some code
$this->sendMail($this->attachedfiles,$customer);
}
$this->response($this->success);
此代码循环数组,并使用attachedfiles
向每个人发送电子邮件,最后向客户端做出响应
问题是这需要很多时间。所以我试过这样的方法:
$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++;
}
在这种格式下,邮件不会被发送,你知道会有什么问题吗?你可以使用Swift Mailer或PHPMailer。 使用此库,您可以轻松地通过一个操作向多个电子邮件发送邮件。
sendMail使用
PHPMailer
使用PHPMailer,您可以添加许多收件人,如下所示:$mail->addAddress('joe@example.net'); $邮件->地址('joe2@example.net'); 尽管如此,发送电子邮件需要时间,因为您的邮件需要通过网络传输,具有一定大小和附件。您可以简单地发送附件的链接,而不是将附件发送到电子邮件中,这种方式将是def。更快。此外,如果客户基础很大,考虑后台作业和队列。