function f_SEND($t_email = '', $t_asunto = '', $t_contenido) { require_once '../modelo/phpmailer/class.phpmailer.php'; $a_email = new phpmailer(); $a_email->Mailer = "smtp"; $a_email->Host = ""; $a_email->SMTPAuth = true; $a_email->Port = '465'; $a_email->CharSet = 'utf8'; $a_email->Username = ''; $a_email->Password = ''; $a_email->From = ''; $a_email->FromName = '' . utf8_decode(''); //escribir la el contenido del correo //dirección destino $a_correo = '' . $t_email; $a_email->addAddress($a_correo); $a_email->Subject = '' . utf8_decode('' . $t_asunto); $a_email->AddEmbeddedImage('../imagenes/inen_header.png', 'logoinen', 'inen_header.png'); $a_email->IsHTML(true); $a_email->Body = "<p><img src=\"cid:logoinen\" /></p><p>" . utf8_decode('' . $t_contenido) . "</p>"; $a_email->AltBody = ' '; if ($a_email->send()) { echo "</br>Mensaje enviado correctamente.</br>"; } else { echo "<br/><strong>Información:</strong><br/>" . $a_email->ErrorInfo; } }
if (!($dir = opendir("admin/templates/" . $template . "/images/"))) { echo "Error : Unable to access the templates directory !!!</body></html>"; return; } while ($name = readdir($dir)) { if ($name == "." || $name == "..") { continue; } if (is_file("admin/templates/" . $template . "/images/" . $name)) { $ext = array(); $ext = explode(".", $name, strlen($name)); $extn = $ext[count($ext) - 1]; if (strtolower($extn) == "gif") { if ($email_images == "yes") { $html = str_replace("images/" . $name, "cid:" . md5($name), $html); $mail->AddEmbeddedImage("admin/templates/" . $template . "/images/" . $name, md5($name), '', 'base64', "image/gif"); } else { $html = str_replace("images/" . $name, $website . $main_dir . "admin/templates/" . $template . "/images/" . $name, $html); } } if (strtolower($extn) == "jpg") { if ($email_images == "yes") { $html = str_replace("images/" . $name, "cid:" . md5($name), $html); $mail->AddEmbeddedImage("admin/templates/" . $template . "/images/" . $name, md5($name), '', 'base64', "image/jpeg"); } else { $html = str_replace("images/" . $name, $website . $main_dir . "admin/templates/" . $template . "/images/" . $name, $html); } } if (strtolower($extn) == "png") { if ($email_images == "yes") { $html = str_replace("images/" . $name, "cid:" . md5($name), $html);
/** * Funcion que envia el correo * @param $to * @param $cc * @param $cco * @param $subject * @param $from * @param $body * Valida que los destinatarios con sus * respectivos nombres y asunto tengan * un formato válido. * * Se envia correo a los destinatarios recibidos * Retorna boolean true al enviar correo exitoso. * @return boolean */ public function Send($value = '') { $to = $this->to; // Cuenta que los destinatarios to no sean mas de 5. $contador = count($to); if ($contador > 5) { $this->errors = "MAX_FIVE_RECIPIENTS"; return 0; } // Se evoca la funcion validadora para comprobar // los formatos de correo y respectivos nombres. $t = $this->Valida_dest($to); if ($t == 0) { return 0; } $cc = $this->cc; // Cuenta que los destinatarios cc(si hubiese) no sean mas de 5. $contador = count($cc); if ($contador > 5) { $this->errors = "MAX_FIVE_COPYS"; return 0; } // Se evoca la funcion validadora para comprobar // los formatos de correo y respectivos nombres(si hubiese). $c = $this->Valida_dest($cc); if ($c == 0) { return 0; } $cco = $this->cco; // Cuenta que los destinatarios cco(si hubiese) no sean mas de 5. $contador = count($cco); if ($contador > 20) { $this->errors = "MAX_TWENTY_BCC"; return 0; } // Se evoca la funcion validadora para comprobar // los formatos de correo y respectivos nombres(si hubiese). $co = $this->Valida_dest($cco); if ($co == 0) { return 0; } $subject = $this->subject; // Se evoca la funcion validadora para comprobar // el formato del asunto. if (!empty($subject)) { $s = $this->Valida_headers($subject); if ($s == 0) { return 0; } foreach ($subject as $key => $value) { $subject = $value; } } $from = $this->from; if (!empty($from)) { // Se evoca la funcion validadora para comprobar // el formato del correo y nombre del remitente. $def_from = 1; $f = $this->Valida_headers($from); if ($f == 0) { return 0; } $from = array(); foreach ($f as $key => $value) { $from[] = $value; } } else { $def_from = 0; } $replyto = $this->replyto; if (!empty($replyto)) { $rp = 1; // Se evoca la funcion validadora para comprobar // el formato del correo y nombre para informar // sobre correos fallidos(si hubiese). $rt = $this->Valida_headers($replyto); if ($rt == 0) { return 0; } $replyto = array(); foreach ($rt as $key => $value) { $replyto[] = $value; } } else { $rp = 0; } $body = $this->body; // Recibimos las rutas y alias de los archivos adjuntos // necesarios a enviar en el correo (si hubiese). $attachment = $this->attachment; if (!empty($attachment)) { $z = 2; $attachment_r = array(); $attachment_t = array(); foreach (new ArrayIterator($this->attachment) as $route => $type) { $attachment_r[] = $route; $attachment_t[] = $type; } } else { $z = 1; } // Recibimos las rutas y alias de las imagenes embebidas en un html // necesarios a enviar en el correo (si hubiese). $embeddedimg = $this->embeddedimg; if (!empty($embeddedimg)) { $y = 2; $embeddedimg_r = array(); $embeddedimg_t = array(); foreach (new ArrayIterator($this->embeddedimg) as $route => $type) { $embeddedimg_r[] = $route; $embeddedimg_t[] = $type; } } else { $y = 1; } // si se deseára configurar los parametros de el dominio // y cuenta de correo default, aquí se recibirian los parámetros. $port = $this->port; $smtp_secure = $this->smtp_secure; $auth = $this->auth; $host = $this->host; $username = $this->username; $password = $this->password; $mail = new phpmailer(); $mail->CharSet = 'UTF-8'; $mail->Mailer = "smtp"; $mail->IsSMTP(); ini_set('max_execution_time', 600); $mail->SMTPAuth = true; // si se indica un puerto este se utilizara, // de lo contrario su usará el default. if (empty($port)) { $mail->Port = 465; } else { $mail->Port = $port; } // si se indica un tipo de seguridad este se utilizara, // de lo contrario su usará el default. if (empty($smtp_secure)) { $mail->SMTPSecure = 'ssl'; } else { $mail->SMTPSecure = $smtp_secure; } // si se indica un cambio en la autenticación este se utilizara, // de lo contrario su usará el default. if (empty($auth)) { $mail->SMTPAuth = true; } else { $mail->SMTPAuth = $auth; } // si se indica un host este se utilizara, // de lo contrario su usará el default. if (empty($host)) { $mail->Host = "securemail.aplus.net"; } else { $mail->Host = $host; } // si se indica un usuario este se utilizara, // de lo contrario su usará el default. if (empty($username)) { $mail->Username = "******"; } else { $mail->Username = $username; } // si se indica un password este se utilizara, // de lo contrario su usará el default. if (empty($password)) { $mail->Password = "******"; } else { $mail->Password = $password; } $mail->Subject = $subject; if ($def_from == 1) { $mail->SetFrom($from[1], $from[0]); } else { $mail->SetFrom('*****@*****.**', 'Global Corporation'); } if ($rp == 1) { $mail->AddReplyTo($replyto[1], $replyto[0]); } $mail->Body = " "; $mail->MsgHTML($body); if ($z == 2) { for ($a = 0; $a < count($attachment_r); $a++) { $mail->AddAttachment($attachment_r[$a], $attachment_t[$a]); } } if ($y == 2) { for ($a = 0; $a < count($embeddedimg_r); $a++) { $mail->AddEmbeddedImage($embeddedimg_r[$a], $embeddedimg_t[$a]); } } for ($i = 0; $i < count($to); $i++) { $a = $to[$i]; $mail->AddAddress($a['direccion'], $a['nombre']); } for ($j = 0; $j < count($cc); $j++) { $a = $cc[$j]; $mail->AddCC($a['direccion'], $a['nombre']); } for ($k = 0; $k < count($cco); $k++) { $a = $cco[$k]; $mail->AddBCC($a['direccion'], $a['nombre']); } $mail->IsHTML(true); if ($mail->Send()) { return true; } else { $this->errors = "SEND_MAIL_ERROR " . $mail->ErrorInfo; return 0; } }
function enviarMail($destino, $asunto, $cuerpo) { $mail = new phpmailer(); // Introducimos la información del remitente del mensaje $mail->From = _FROM; $mail->FromName = "UNCSurveys"; // y los destinatarios del mensaje. Podemos especificar más de un destinatario $mail->AddAddress($destino, "UNCSurveys"); $mail->IsHTML(true); // enviar como HTML // Añadimos el mensaje: asunto, cuerpo del mensaje en HTML y en formato // solo texto $mail->AddEmbeddedImage('../img/logo80.png', 'logo_2u', '../img/logo80.png', 'base64', 'image/png'); $mail->AddEmbeddedImage('../img/logo300.png', 'logo_2uP', '../img/logo300.png', 'base64', 'image/png'); $mail->Subject = $asunto; $mail->Body = $cuerpo; //$mail->AltBody = "Y este es el mensaje de solo texto"; // Para los queno pueden recibir en formato HTML $mail->IsSMTP(); // enviar vía SMTP $mail->Host = _SMTP; // Servidores SMTP $mail->SMTPAuth = true; // activar la identificacín SMTP $mail->Username = _EMAILUSR; // usuario SMTP $mail->Password = _EMAILPASS; // clave SMTP $mail->Port = _PUERTO; $mail->SMTPSecure = "ssl"; //print_r($mail); if (!$mail->Send()) { echo "El mensaje no se ha podido enviar - Error: " . $mail->ErrorInfo; exit; return false; } else { return true; } }
/** * Set up and send an email * * The array argument is searched for the following indices: * key The key of any mail template to be used * section The module to initialize for (mandatory when key is set) * sender The sender name * from The sender e-mail address * to The recipient e-mail address(es), comma separated * reply The reply-to e-mail address * cc The carbon copy e-mail address(es), comma separated * bcc The blind carbon copy e-mail address(es), comma separated * subject The message subject * message The plain text message body * message_html The HTML message body * html If this evaluates to true, turns on HTML mode * attachments An array of file paths to attach. The array keys may * be used for the paths, and the values for the name. * If the keys are numeric, the values are regarded as paths. * inline An array of inline (image) file paths to attach. * If this is used, HTML mode is switched on automatically. * search The array of patterns to be replaced by... * replace The array of replacements for the patterns * substitution A more complex structure for replacing placeholders * and/or complete blocks, conditionally or repeatedly. * If the key index is present, the corresponding mail template is loaded * first. Other indices present (sender, from, to, subject, message, etc.) * will override the template fields. * Missing mandatory fields are filled with the * default values from the global $_CONFIG array (sender, from, to), * or some core language variables (subject, message). * A simple {@see str_replace()} is used for the search and replace * operation, and the placeholder names are quoted in the substitution, * so you cannot use regular expressions. * More complex substitutions including repeated blocks may be specified * in the substitution subarray of the $arrField parameter value. * The e-mail addresses in the To: field will be used as follows: * - Groups of addresses are separated by semicola (;) * - Single addresses are separated by comma (,) * All recipients of any single group are added to the To: field together, * Groups are processed separately. So, if your To: looks like * a@a.com,b@b.com;c@c.com,d@d.com * a total of two e-mails will be sent; one to a and b, and a second one * to c and d. * Addresses for copies (Cc:) and blind copies (Bcc:) are added to all * e-mails sent, so if your e-mail is in the Cc: or Bcc: field in the * example above, you will receive two copies. * Note: The attachment paths must comply with the requirements for * file paths as defined in the {@see File} class version 2.2.0. * @static * @param array $arrField The array of template fields * @return boolean True if the mail could be sent, * false otherwise * @author Reto Kohli <*****@*****.**> */ static function send($arrField) { global $_CONFIG; //, $_CORELANG; if (!\Env::get('ClassLoader')->loadFile(ASCMS_LIBRARY_PATH . '/phpmailer/class.phpmailer.php')) { \DBG::log("MailTemplate::send(): ERROR: Failed to load phpMailer"); return false; } $objMail = new \phpmailer(); if (!empty($_CONFIG['coreSmtpServer']) && \Env::get('ClassLoader')->loadFile(ASCMS_CORE_PATH . '/SmtpSettings.class.php')) { $arrSmtp = \SmtpSettings::getSmtpAccount($_CONFIG['coreSmtpServer']); if ($arrSmtp) { $objMail->IsSMTP(); $objMail->SMTPAuth = true; $objMail->Host = $arrSmtp['hostname']; $objMail->Port = $arrSmtp['port']; $objMail->Username = $arrSmtp['username']; $objMail->Password = $arrSmtp['password']; } } if (empty($arrField['lang_id'])) { $arrField['lang_id'] = FRONTEND_LANG_ID; } $section = isset($arrField['section']) ? $arrField['section'] : null; $arrTemplate = null; if (empty($arrField['key'])) { $arrTemplate = self::getEmpty(); } else { $arrTemplate = self::get($section, $arrField['key'], $arrField['lang_id']); if (empty($arrTemplate)) { \DBG::log("MailTemplate::send(): WARNING: No Template for key {$arrField['key']} (section {$section})"); return false; } } $search = isset($arrField['search']) && is_array($arrField['search']) ? $arrField['search'] : null; $replace = isset($arrField['replace']) && is_array($arrField['replace']) ? $arrField['replace'] : null; $substitution = isset($arrField['substitution']) && is_array($arrField['substitution']) ? $arrField['substitution'] : null; //echo("Substitution:<br />".nl2br(var_export($arrField['substitution'], true))."<hr />"); $strip = empty($arrField['do_not_strip_empty_placeholders']); // Replace node placeholders generated by Wysiwyg $arrTemplate['message_html'] = preg_replace('/\\[\\[NODE_([a-zA-Z_0-9]*)\\]\\]/', '{NODE_$1}', $arrTemplate['message_html']); \LinkGenerator::parseTemplate($arrTemplate['message_html'], true); foreach ($arrTemplate as $field => &$value) { if ($field == 'inline' || $field == 'attachments') { continue; } if (isset($arrField[$field])) { $value = $arrField[$field]; } if (empty($value) || is_numeric($value)) { continue; } // TODO: Fix the regex to produce proper "CR/LF" in any case. // Must handle any of CR, LF, CR/LF, and LF/CR! // preg_replace('/[\015\012]/', "\015\012", $value); if ($search) { // we need to replace raw data with HTML entities // for HTML-body of email if ($field == 'message_html') { foreach ($search as $index => $searchTerm) { $value = str_replace($searchTerm, contrexx_raw2xhtml($replace[$index]), $value); } } else { $value = str_replace($search, $replace, $value); } } if ($substitution) { $convertToHtmlEntities = false; if ($field == 'message_html') { $convertToHtmlEntities = true; } self::substitute($value, $substitution, $convertToHtmlEntities); } if ($strip) { self::clearEmptyPlaceholders($value); } } //DBG::log("MailTemplate::send(): Substituted: ".var_export($arrTemplate, true)); //echo("MailTemplate::send(): Substituted:<br /><pre>".nl2br(htmlentities(var_export($arrTemplate, true), ENT_QUOTES, CONTREXX_CHARSET))."</PRE><hr />"); //die();//return true; // Use defaults for missing mandatory fields // if (empty($arrTemplate['sender'])) // $arrTemplate['sender'] = $_CONFIG['coreAdminName']; if (empty($arrTemplate['from'])) { \DBG::log("MailTemplate::send(): INFO: Empty 'from:', falling back to config"); $arrTemplate['from'] = $_CONFIG['coreAdminEmail']; } if (empty($arrTemplate['to'])) { \DBG::log("MailTemplate::send(): INFO: Empty 'to:', falling back to config"); $arrTemplate['to'] = $_CONFIG['coreAdminEmail']; } // if (empty($arrTemplate['subject'])) // $arrTemplate['subject'] = $_CORELANG['TXT_CORE_MAILTEMPLATE_NO_SUBJECT']; // if (empty($arrTemplate['message'])) // $arrTemplate['message'] = $_CORELANG['TXT_CORE_MAILTEMPLATE_NO_MESSAGE']; $objMail->FromName = $arrTemplate['sender']; $objMail->From = $arrTemplate['from']; $objMail->Subject = $arrTemplate['subject']; $objMail->CharSet = CONTREXX_CHARSET; // $objMail->IsHTML(false); if ($arrTemplate['html']) { $objMail->IsHTML(true); $objMail->Body = $arrTemplate['message_html']; $objMail->AltBody = $arrTemplate['message']; } else { $objMail->Body = $arrTemplate['message']; } foreach (preg_split('/\\s*,\\s*/', $arrTemplate['reply'], null, PREG_SPLIT_NO_EMPTY) as $address) { $objMail->AddReplyTo($address); } // foreach (preg_split('/\s*,\s*/', $arrTemplate['to'], null, PREG_SPLIT_NO_EMPTY) as $address) { // $objMail->AddAddress($address); // } foreach (preg_split('/\\s*,\\s*/', $arrTemplate['cc'], null, PREG_SPLIT_NO_EMPTY) as $address) { $objMail->AddCC($address); } foreach (preg_split('/\\s*,\\s*/', $arrTemplate['bcc'], null, PREG_SPLIT_NO_EMPTY) as $address) { $objMail->AddBCC($address); } // Applicable to attachments stored with the MailTemplate only! $arrTemplate['attachments'] = self::attachmentsToArray($arrTemplate['attachments']); //DBG::log("MailTemplate::send(): Template Attachments: ".var_export($arrTemplate['attachments'], true)); // Now the MailTemplates' attachments index is guaranteed to // contain an array. // Add attachments from the parameter array, if any. if (isset($arrField['attachments']) && is_array($arrField['attachments'])) { foreach ($arrField['attachments'] as $path => $name) { // if (empty($path)) $path = $name; // if (empty($name)) $name = basename($path); $arrTemplate['attachments'][$path] = $name; //DBG::log("MailTemplate::send(): Added Field Attachment: $path / $name"); } } //DBG::log("MailTemplate::send(): All Attachments: ".var_export($arrTemplate['attachments'], true)); foreach ($arrTemplate['attachments'] as $path => $name) { if (is_numeric($path)) { $path = $name; } $objMail->AddAttachment(ASCMS_DOCUMENT_ROOT . '/' . $path, $name); } $arrTemplate['inline'] = self::attachmentsToArray($arrTemplate['inline']); if ($arrTemplate['inline']) { $arrTemplate['html'] = true; } foreach ($arrTemplate['inline'] as $path => $name) { if (is_numeric($path)) { $path = $name; } $objMail->AddEmbeddedImage(ASCMS_DOCUMENT_ROOT . '/' . $path, uniqid(), $name); } if (isset($arrField['inline']) && is_array($arrField['inline'])) { $arrTemplate['html'] = true; foreach ($arrField['inline'] as $path => $name) { if (is_numeric($path)) { $path = $name; } $objMail->AddEmbeddedImage(ASCMS_DOCUMENT_ROOT . '/' . $path, uniqid(), $name); } } //die("MailTemplate::send(): Attachments and inlines<br />".var_export($objMail, true)); $objMail->CharSet = CONTREXX_CHARSET; $objMail->IsHTML($arrTemplate['html']); //DBG::log("MailTemplate::send(): Sending: ".nl2br(htmlentities(var_export($objMail, true), ENT_QUOTES, CONTREXX_CHARSET))."<br />Sending...<hr />"); $result = true; foreach (preg_split('/\\s*;\\s*/', $arrTemplate['to'], null, PREG_SPLIT_NO_EMPTY) as $addresses) { $objMail->ClearAddresses(); foreach (preg_split('/\\s*[,]\\s*/', $addresses, null, PREG_SPLIT_NO_EMPTY) as $address) { $objMail->AddAddress($address); } //DBG::log("MailTemplate::send(): ".var_export($objMail, true)); // TODO: Comment for test only! $result &= $objMail->Send(); // TODO: $objMail->Send() seems to sometimes return true on localhost where // sending the mail is actually impossible. Dunno why. } return $result; }
function emailSend($data) { $stime = array_sum(explode(' ', microtime())); require_once "getmxrr.php"; $smtp =& $this->params; $mail = new phpmailer(); $mail->Mailer = "smtp"; $mail->From = isset($data['from']) & !empty($data['from']) ? $data['from'] : '*****@*****.**'; $mail->FromName = isset($data['fromName']) & !empty($data['fromName']) ? $data['fromName'] : 'RuSoft'; $mail->Sender = isset($data['from']) & !empty($data['from']) ? $data['from'] : '*****@*****.**'; $mail->Host = $smtp['host']; $mail->CharSet = $smtp['charset']; $mail->Encoding = $smtp['encoding']; $mail->Port = $smtp['port']; $mail->SMTPAuth = $smtp['auth']; $mail->Subject = isset($data['subj']) & !empty($data['subj']) ? $data['subj'] : ''; if ($smtp['auth']) { $mail->Username = $smtp['user']; $mail->Password = $smtp['pass']; } // HTML body if (isset($data['mess']['html']) & !empty($data['mess']['html'])) { $body = $data['mess']['html']; $mail->isHTML(true); } // Plain text body (for mail clients that cannot read HTML) if (isset($data['mess']['text']) & !empty($data['mess']['text'])) { $text_body = $data['mess']['text']; $mail->isHTML(false); } $mail->AltBody = isset($text_body) ? $text_body : ''; $mail->Body = isset($body) ? $body : (isset($text_body) ? $text_body : ''); $i = 1; // порядковый номер файла //добавляем файлы прикрепленные файлы if (isset($data['attachment']) & !empty($data['attachment'])) { foreach ($data['attachment'] as $k => $item) { if (isset($item['binary']) & !empty($item['binary'])) { $mail->AddStringAttachment($item["binary"], isset($item["name"]) & !empty($item["name"]) ? $item["name"] : 'file' . $i, $smtp['encoding']); $i++; } elseif (isset($item['path']) & !empty($item['path'])) { $mail->AddAttachment($item["path"], isset($item["name"]) & !empty($item["name"]) ? $item["name"] : 'file' . $i, $smtp['encoding']); $i++; } } } // добавляем файлы, отображаемые на странице if (isset($data['embedded']) & !empty($data['embedded'])) { foreach ($data['embedded'] as $k => $item) { if (isset($item['path']) & !empty($item['path'])) { $mail->AddEmbeddedImage($item["path"], isset($item["cid"]) & !empty($item["cid"]) ? $item["cid"] : $i, isset($item["name"]) & !empty($item["name"]) ? $item["name"] : 'file' . $i, $smtp['encoding']); $i++; } } } //pr($mail); //на данном этапе имеется уже собранное письмо и нам необходимо определить mx серверы для отправки...для каждого письма. //чтобы повторно не искать серверы в момент отправки для каждого... //сохраняем для каждого домена один и тот же сервер $mxsrvs = array(); $mxemails = array(); $debug['ctime'] = round((array_sum(explode(' ', microtime())) - $stime) * 1000, 2) . " ms"; foreach ($data['to'] as $email => $name) { //берем чисто host if (!$this->_is_valid_email($email)) { $debug['emails'][$email]['error'] = "неправильно указан email адрес."; continue; } $host = substr($email, strpos($email, "@") + 1); $domains = explode(".", $host); foreach ($domains as $level => $domain) { $address = implode(".", $domains); if (!key_exists($address, $mxsrvs)) { $time = array_sum(explode(' ', microtime())); if (getmxrr_portable($address, $mxhosts, $preference) == true) { array_multisort($preference, $mxhosts); } $debug['emails'][$email]['mxtime'] = round((array_sum(explode(' ', microtime())) - $time) * 1000, 2) . " ms"; if (!empty($mxhosts)) { $mxhosts[] = $smtp['host']; //потому что shadow тормознутый сервак if (in_array('shadow.rusoft.ru', $mxhosts)) { unset($mxhosts[0]); } //чтобы включить рассылку на smtp серверы получателей, необходимо закоментировать следующую строчку $mxhosts = array_reverse($mxhosts); $mxsrvs[$address] = $mxhosts; $mxemails[$email] =& $mxsrvs[$address]; $debug['emails'][$email]['mxsrvs'] =& $mxsrvs[$address]; break; } else { unset($domains[$level]); } } else { $debug['emails'][$email]['mxtime'] = 'cache(0 ms)'; $mxemails[$email] =& $mxsrvs[$address]; $debug['emails'][$email]['mxsrvs'] =& $mxsrvs[$address]; } } } //получены все mx северы и теперь начинаем отправку по списку foreach ($mxemails as $email => $mxs) { //проверяем email адрес на существование и работу mx сервера //можно включить проверку, но это 1) замедляет, 2) вероятность очень низкая //$this->checkEmail($email, $mxs, $debug); $mail->AddAddress($email, $name); foreach ($mxs as $k => $host) { $mail->Host = $host; $time = array_sum(explode(' ', microtime())); $status = $mail->Send(); $debug['emails'][$email]['sendtime'] = round((array_sum(explode(' ', microtime())) - $time) * 1000, 2) . " ms"; $debug['emails'][$email]['status'] = $status; if ($status) { $debug['emails'][$email]['host'] = $host; break; } } $mail->ClearAddresses(); } $debug['time'] = round((array_sum(explode(' ', microtime())) - $stime) * 1000, 2) . " ms"; if (function_exists('log_notice')) { //скидываем в лог информацию о отправленных сообщениях $str = "<b>Были отправлены следующие сообщения:</b><br>Время генерации шалона для отправки: " . $debug['ctime'] . "<br>Общее время: " . $debug['time'] . "<br><b>Адреса:</b><br>"; foreach ($debug['emails'] as $k => $v) { $str .= "<br> <b><font color='blue'>" . $k . "</font></b>"; $str .= "<br> Определение smtp серверов: " . $v['mxtime']; $str .= "<br> Отправлено через: " . $v['host']; $str .= "<br> Время отправления: " . $v['sendtime']; $str .= "<br> Статус: " . ($v['status'] ? '<font color="green">успешно</font>' : '<font color="red">неудачно</font>'); } log_notice('email', false, $str); } //$status = true; // Clear attachments for next loop $mail->ClearAttachments(); if ($status) { return true; } return false; }