function sendMail(eZMail $mail) { $ini = eZINI::instance(); $sendmailOptions = ''; $emailFrom = $mail->sender(); $emailSender = $emailFrom['email']; if (!$emailSender || count($emailSender) <= 0) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); } if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'AdminEmail'); } if (!eZMail::validate($emailSender)) { $emailSender = false; } $isSafeMode = ini_get('safe_mode'); if ($isSafeMode and $emailSender and $mail->sender() == false) { $mail->setSenderText($emailSender); } $filename = time() . '-' . mt_rand() . '.mail'; $data = preg_replace('/(\\r\\n|\\r|\\n)/', "\r\n", $mail->headerText() . "\n" . $mail->body()); $returnedValue = eZFile::create($filename, 'var/log/mail', $data); if ($returnedValue === false) { eZDebug::writeError('An error occurred writing the e-mail file in var/log/mail', __METHOD__); } return $returnedValue; }
function sendMail(eZMail $mail) { $ini = eZINI::instance(); $sendmailOptions = ''; $emailFrom = $mail->sender(); $emailSender = isset($emailFrom['email']) ? $emailFrom['email'] : false; if (!$emailSender || count($emailSender) <= 0) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); } if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'AdminEmail'); } if (!eZMail::validate($emailSender)) { $emailSender = false; } $isSafeMode = ini_get('safe_mode') != 0; $sendmailOptionsArray = $ini->variable('MailSettings', 'SendmailOptions'); if (is_array($sendmailOptionsArray)) { $sendmailOptions = implode(' ', $sendmailOptionsArray); } elseif (!is_string($sendmailOptionsArray)) { $sendmailOptions = $sendmailOptionsArray; } if (!$isSafeMode and $emailSender) { $sendmailOptions .= ' -f' . $emailSender; } if ($isSafeMode and $emailSender and $mail->sender() == false) { $mail->setSenderText($emailSender); } if (function_exists('mail')) { $message = $mail->body(); $sys = eZSys::instance(); $excludeHeaders = array('Subject'); // If not Windows PHP mail() implementation, we can not specify a To: header in the $additional_headers parameter, // because then there will be 2 To: headers in the resulting e-mail. // However, we can use "undisclosed-recipients:;" in $to. if ($sys->osType() != 'win32') { $excludeHeaders[] = 'To'; $receiverEmailText = count($mail->ReceiverElements) > 0 ? $mail->receiverEmailText() : 'undisclosed-recipients:;'; } else { $receiverEmailText = $mail->receiverEmailText(); } // If in debug mode, send to debug email address and nothing else if ($ini->variable('MailSettings', 'DebugSending') == 'enabled') { $receiverEmailText = $ini->variable('MailSettings', 'DebugReceiverEmail'); $excludeHeaders[] = 'To'; $excludeHeaders[] = 'Cc'; $excludeHeaders[] = 'Bcc'; } $extraHeaders = $mail->headerText(array('exclude-headers' => $excludeHeaders)); $returnedValue = mail($receiverEmailText, $mail->subject(), $message, $extraHeaders, $sendmailOptions); if ($returnedValue === false) { eZDebug::writeError('An error occurred while sending e-mail. Check the Sendmail error message for further information (usually in /var/log/messages)', __METHOD__); } return $returnedValue; } else { eZDebug::writeWarning("Unable to send mail: 'mail' function is not compiled into PHP.", __METHOD__); } return false; }