/** * @param IEmailMessage $emailMessage */ function Send(IEmailMessage $emailMessage) { if (is_array($emailMessage->To())) { $to = implode(', ', $emailMessage->To()); } else { $to = $emailMessage->To(); } Log::Debug("Sending Email. To: %s\nFrom: %s\nSubject: %s\nBody: %s", $to, $emailMessage->From(), $emailMessage->Subject(), $emailMessage->Body()); }
public function Send(IEmailMessage $emailMessage) { $this->phpMailer->ClearAllRecipients(); $this->phpMailer->ClearReplyTos(); $this->phpMailer->CharSet = $emailMessage->Charset(); $this->phpMailer->Subject = $emailMessage->Subject(); $this->phpMailer->Body = $emailMessage->Body(); $from = $emailMessage->From(); $defaultFrom = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_ADDRESS); $defaultName = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_NAME); $address = empty($defaultFrom) ? $from->Address() : $defaultFrom; $name = empty($defaultName) ? $from->Name() : $defaultName; $this->phpMailer->SetFrom($address, $name); $replyTo = $emailMessage->ReplyTo(); $this->phpMailer->AddReplyTo($replyTo->Address(), $replyTo->Name()); $to = $this->ensureArray($emailMessage->To()); $toAddresses = new StringBuilder(); foreach ($to as $address) { $toAddresses->Append($address->Address()); $this->phpMailer->AddAddress($address->Address(), $address->Name()); } $cc = $this->ensureArray($emailMessage->CC()); foreach ($cc as $address) { $this->phpMailer->AddCC($address->Address(), $address->Name()); } $bcc = $this->ensureArray($emailMessage->BCC()); foreach ($bcc as $address) { $this->phpMailer->AddBCC($address->Address(), $address->Name()); } if ($emailMessage->HasStringAttachment()) { Log::Debug('Adding email attachment %s', $emailMessage->AttachmentFileName()); $this->phpMailer->AddStringAttachment($emailMessage->AttachmentContents(), $emailMessage->AttachmentFileName()); } Log::Debug('Sending %s email to: %s from: %s', get_class($emailMessage), $toAddresses->ToString(), $from->Address()); $success = false; try { $success = $this->phpMailer->Send(); } catch (Exception $ex) { Log::Error('Failed sending email. Exception: %s', $ex); } Log::Debug('Email send success: %d. %s', $success, $this->phpMailer->ErrorInfo); }