/** * @param Job $job * * @return array * @throws \Zend_Mail_Exception */ protected function sendMail(Job $job) { // prepare Transport $clientConfig = static::getConfig('client'); $transport = $this->getTransport($clientConfig['host'], $clientConfig['params']); // Build mail $Email = $this->getMail(); $Email->setSubject($job->getSubject()); $Email->setBodyHtml($job->getBody()); $Email->setBodyText(strip_tags($job->getBody())); $Email->setFrom($job->getFromMail(), $job->getFromName()); $Email->addTo($job->getToMail()); $attachments = $job->getAttachment(); if (!empty($attachments) && is_array($attachments) && count($attachments) > 0) { foreach ($attachments as $key => $attach) { //$at[$key] = $mail->createAttachment(file_get_contents($attachment[Job::T_EMAIL_P_ATTACHMENT__PATH])); $at[$key] = $Email->createAttachment(base64_decode($attach[Job::P_PARAM_ATTACHMENT__PATH])); $at[$key]->filename = $attach[Job::P_PARAM_ATTACHMENT__NAME]; $at[$key]->type = $attach[Job::P_PARAM_ATTACHMENT__TYPE]; $at[$key]->disposition = $attach[Job::P_PARAM_ATTACHMENT__DISPOSITION]; $at[$key]->encoding = $attach[Job::P_PARAM_ATTACHMENT__ENCODING]; $at[$key]->id = $attach[Job::P_PARAM_ATTACHMENT__ID]; } } // Send mail $success = (bool) $Email->send($transport); $response = ['success' => $success]; return $response; }
/** * @param Job $job * * @return array */ protected function sendMail(Job $job) { $mail = $this->getMail(); $mail->isHTML(true); $mail->setFrom($job->getFromMail(), $job->getFromName()); $mail->addAddress($job->getToMail()); $mail->Subject = $job->getSubject(); $mail->Body = $job->getBody(); $mail->AltBody = strip_tags($job->getBody()); $attachments = $job->getAttachment(); if (!empty($attachments) && is_array($attachments) && count($attachments) > 0) { foreach ($attachments as $key => $attach) { if (isset($attach[Job::P_PARAM_ATTACHMENT__NAME])) { $mail->addAttachment($attach[Job::P_PARAM_ATTACHMENT__PATH], $attach[Job::P_PARAM_ATTACHMENT__NAME]); } else { $mail->addAttachment($attach[Job::P_PARAM_ATTACHMENT__PATH]); } } } $isSend = $mail->send(); return ['success' => $isSend]; }