/** * Mainfunction for mail send * * @param unknown_type $emailSender * @param unknown_type $emailSenderName * @param unknown_type $emailReceiver * @param unknown_type $emailReceiverName * @param unknown_type $emailSubject * @param unknown_type $emailBodyArray * @param boolean $isPreview * @param string $emailCharset * @return array */ public function sendEmail($emailSender, $emailSenderName, $emailReceiver, $emailReceiverName, $emailSubject, $emailBodyArray, $isPreview = false, $emailCharset = 'utf-8') { $transportMethod = $this->transportMethod; //$mail = new ezcMailComposer(); $mail = new CjwNewsletterMailComposer(); $mail->charset = $emailCharset; $mail->subjectCharset = $emailCharset; // from and to addresses, and subject $mail->from = new ezcMailAddress(trim($emailSender), $emailSenderName); // returnpath for email bounces $mail->returnPath = new ezcMailAddress(trim($emailSender)); if ($isPreview) { $explodeReceiverArr = explode(';', $emailReceiver); foreach ($explodeReceiverArr as $index => $receiver) { // check if email if ($receiver != '') { $mail->addTo(new ezcMailAddress(trim($receiver), 'NL Test Receiver' . $index)); } } } else { $mail->addTo(new ezcMailAddress(trim($emailReceiver), $emailReceiverName)); } if (array_key_exists('html', $emailBodyArray) == false) { $emailBodyArray['html'] = ''; } if (array_key_exists('text', $emailBodyArray) == false) { $emailBodyArray['text'] = ''; } $mail->subject = $emailSubject; if ($emailBodyArray['html'] == '') { // tue nix - da kein html da ist } else { $mail->htmlText = $emailBodyArray['html']; } // body: plain // $mail->plainText = "Here is the text version of the mail."; if ($emailBodyArray['text'] == '') { // $mail->plainText = "Text version of this mail does not exists."; } else { $mail->plainText = $emailBodyArray['text']; } $emailContentType = ''; if ($emailBodyArray['html'] != '' && $emailBodyArray['text'] != '') { $emailContentType = 'multipart/alternative'; } else { if ($emailBodyArray['html'] != '') { $emailContentType = 'text/html'; } elseif ($emailBodyArray['text'] != '') { $emailContentType = 'text/plain'; } } // http://ezcomponents.org/docs/api/latest/introduction_Mail.html#mta-qmail // HeaderLineEnding=auto // CRLF - windows - \r\n // CR - mac - \r // LF - UNIX-MACOSX - \n // default LF //ezcMailTools::setLineBreak( "\n" ); ezcMailTools::setLineBreak($this->HeaderLineEnding); // set 'x-cjwnl-' mailheader foreach ($this->ExtraEmailHeaderItemArray as $key => $value) { $mail->setHeader($key, $value); } $mail->build(); $transport = new CjwNewsletterTransport($transportMethod); $sendResult = $transport->send($mail); $emailResult = array('send_result' => $sendResult, 'email_sender' => $emailSender, 'email_receiver' => $emailReceiver, 'email_subject' => $emailSubject, 'email_content_type' => $emailContentType, 'email_charset' => $emailCharset, 'transport_method' => $transportMethod); // ok if ($sendResult) { CjwNewsletterLog::writeInfo('email send ok', 'CjwNewsletterMail', 'sendEmail', $emailResult); } else { CjwNewsletterLog::writeError('email send failed', 'CjwNewsletterMail', 'sendEmail', $emailResult); } // $LogFile->write( $message, $logName, $logFolder ); return $emailResult; }
/** * Mainfunction for mail send * * @param unknown_type $emailSender * @param unknown_type $emailSenderName * @param unknown_type $emailReceiver * @param unknown_type $emailReceiverName * @param unknown_type $emailSubject * @param unknown_type $emailBodyArray * @param boolean $isPreview * @param string $emailCharset * @return array */ public function sendEmail($emailSender, $emailSenderName, $emailReceiver, $emailReceiverName, $emailSubject, $emailBodyArray, $isPreview = false, $emailCharset = 'utf-8', $emailReplyTo = false, $emailReturnPath = false) { $transportMethod = $this->transportMethod; //$mail = new ezcMailComposer(); $mail = new CjwNewsletterMailComposer(); // Encode the UTF-8 as base64 or QUOTED_PRINTABLE for 7 bit MTAs // $mail->encoding = ezcMail::BASE64; // $mail->encoding = ezcMail::QUOTED_PRINTABLE; $mail->encoding = $this->ContentTransferEncoding; $mail->charset = $emailCharset; $mail->subjectCharset = $emailCharset; // from and to addresses, and subject $mail->from = new ezcMailAddress(trim($emailSender), $emailSenderName, $mail->charset); // returnpath for email bounces if (!($emailReturnPath && $emailReturnPath != '')) { $mail->returnPath = $mail->from; } else { $mail->returnPath = new ezcMailAddress(trim($emailReturnPath), '', $mail->charset); } $mail->setHeader('Errors-To', $mail->returnPath); // reply-to if (!($emailReplyTo && $emailReplyTo != '')) { $mail->setHeader('Reply-To', $mail->from); } else { $mail->setHeader('Reply-To', new ezcMailAddress(trim($emailReplyTo), '', $mail->charset)); } if ($isPreview) { $explodeReceiverArr = explode(';', $emailReceiver); foreach ($explodeReceiverArr as $index => $receiver) { // check if email if ($receiver != '') { $mail->addTo(new ezcMailAddress(trim($receiver), 'NL Test Receiver' . $index, $mail->charset)); } } } else { $mail->addTo(new ezcMailAddress(trim($emailReceiver), $emailReceiverName, $mail->charset)); } if (array_key_exists('html', $emailBodyArray) == false) { $emailBodyArray['html'] = ''; } if (array_key_exists('text', $emailBodyArray) == false) { $emailBodyArray['text'] = ''; } $mail->subject = $emailSubject; if ($emailBodyArray['html'] == '') { // tue nix - da kein html da ist } else { $mail->htmlText = $emailBodyArray['html']; } // body: plain // $mail->plainText = "Here is the text version of the mail."; if ($emailBodyArray['text'] == '') { // $mail->plainText = "Text version of this mail does not exists."; } else { $mail->plainText = $emailBodyArray['text']; } $emailContentType = ''; if ($emailBodyArray['html'] != '' && $emailBodyArray['text'] != '') { $emailContentType = 'multipart/alternative'; } else { if ($emailBodyArray['html'] != '') { $emailContentType = 'text/html'; } elseif ($emailBodyArray['text'] != '') { $emailContentType = 'text/plain'; } } // http://ezcomponents.org/docs/api/latest/introduction_Mail.html#mta-qmail // HeaderLineEnding=auto // CRLF - windows - \r\n // CR - mac - \r // LF - UNIX-MACOSX - \n // default LF //ezcMailTools::setLineBreak( "\n" ); ezcMailTools::setLineBreak($this->HeaderLineEnding); // set 'x-cjwnl-' mailheader foreach ($this->ExtraEmailHeaderItemArray as $key => $value) { $mail->setHeader($key, $value, $mail->charset); } $mail->build(); $transport = new CjwNewsletterTransport($transportMethod); $sendResult = $transport->send($mail); $emailResult = array('send_result' => $sendResult, 'email_sender' => $emailSender, 'email_receiver' => $emailReceiver, 'email_subject' => $emailSubject, 'email_content_type' => $emailContentType, 'email_charset' => $emailCharset, 'transport_method' => $transportMethod); // ok if ($sendResult === true) { CjwNewsletterLog::writeInfo('email send ok', 'CjwNewsletterMail', 'sendEmail', $emailResult); } else { // An error occured while sending or receiving mail. RCPT TO failed with error: 450 4.1.2 // <*****@*****.**>: Recipient address rejected: Domain not found // is string ' 450 ' included in emailResult $searchString = ' 450 '; $addErrorMessage = ''; if (strpos($sendResult, $searchString) !== false) { // check if we found an email nl user for emailReceiver $nlUserToBounce = CjwNewsletterUser::fetchByEmail($emailReceiver); if (is_object($nlUserToBounce)) { // hardbounce user // alle active element will be aborted, too $nlUserToBounce->setBounced(true); $emailResult['nluser_id'] = $nlUserToBounce->attribute('id'); $addErrorMessage = ' - HARD BOUNCE (450)'; } else { $addErrorMessage = ' - NL User for email not found'; } } CjwNewsletterLog::writeError('email send failed to ' . $emailReceiver . $addErrorMessage, 'CjwNewsletterMail', 'sendEmail', $emailResult); } // $LogFile->write( $message, $logName, $logFolder ); return $emailResult; }