Пример #1
0
 public function send($do_send, $raw_message = '')
 {
     //--
     if (strlen($this->smtp_helo) <= 0) {
         // fix
         $this->smtp_helo = '127.0.0.1';
     }
     //end if
     //--
     $tmp_explode_arr = (array) explode('@', (string) $this->from);
     $tmp_name = trim($tmp_explode_arr[0]);
     // used for from name in the case it is empty
     $tmp_domain = trim($tmp_explode_arr[1]);
     // used for message ID
     //--
     if (strlen($this->namefrom) > 0) {
         $tmp_name = SmartUnicode::deaccent_str($this->namefrom);
     } else {
         $tmp_name = ucwords(str_replace(array('.', '-', '_'), array(' ', ' ', ' '), (string) $tmp_name));
     }
     //end if
     //--
     $this->mime_message = '';
     // init
     //--
     $this->mime_message .= 'Return-Path: ' . '<' . $this->from_return . '>' . "\r\n";
     $this->mime_message .= 'From: ' . $tmp_name . ' <' . $this->from . '>' . "\r\n";
     // [ucwords] is safe here as the name is ISO-8859-1 (1st part of email address)
     $this->mime_message .= 'Date: ' . date('D, d M Y H:i:s O') . "\r\n";
     $this->mime_message .= 'To: ' . $this->to . "\r\n";
     //--
     if (is_array($this->cc)) {
         for ($z = 0; $z < Smart::array_size($this->cc); $z++) {
             if (strlen($this->cc[$z]) > 0) {
                 $this->mime_message .= "Cc: " . $this->cc[$z] . "\r\n";
             }
             //end if
         }
         //end for
     } elseif (strlen($this->cc) > 0) {
         $this->mime_message .= "Cc: " . $this->cc . "\r\n";
     }
     //end if
     if ((string) $do_send != 'yes') {
         if (strlen($this->bcc) > 0) {
             $this->mime_message .= "BCc: " . $this->bcc . "\r\n";
         }
         //end if
     }
     //end if
     //--
     $this->mime_message .= "Subject: " . $this->prepare_subject($this->subject) . "\r\n";
     //--
     switch ((string) $this->priority) {
         case '1':
             $this->mime_message .= "X-Priority: " . '1' . "\r\n";
             //high
             break;
         case '5':
             $this->mime_message .= "X-Priority: " . '5' . "\r\n";
             //low
             break;
         case '3':
         default:
             $this->mime_message .= "X-Priority: " . '3' . "\r\n";
             //normal
     }
     //end switch
     //--
     $this->mime_message .= "X-Mailer: " . 'SmartFramework Mailer (' . SMART_FRAMEWORK_VERSION . ')' . "\r\n";
     $this->mime_message .= "MIME-Version: 1.0 " . '(SmartFramework Mime-Message v.2016.02.01)' . "\r\n";
     $this->mime_message .= "Message-Id: " . '<ID-' . Smart::uuid_10_seq() . '-' . Smart::uuid_10_str() . '-' . Smart::uuid_10_num() . '@' . Smart::safe_validname($tmp_domain) . '>' . "\r\n";
     //--
     if (strlen($this->headers) > 0) {
         $this->mime_message .= $this->headers;
         // must be end by \r\n
     }
     //end if
     //--
     if (strlen($raw_message) <= 0) {
         //--
         if (strlen($this->body) > 0) {
             //--
             if ($this->is_html == false) {
                 $this->add_attachment($this->body, '', 'text/plain', 'inline');
             } else {
                 $this->add_attachment('This is a MIME Message in HTML Format.', 'alternative-part.txt', 'text/plain', 'inline');
                 // antiSPAM needs an alternate body
                 $this->add_attachment($this->body, '', 'text/html', 'inline');
             }
             //end else
             //--
         }
         //end if
         //--
         $this->mime_message .= $this->build_multipart() . "\r\n";
         //--
     } else {
         //-- RAW (get as is)
         $this->mime_message .= $raw_message . "\r\n";
         //--
     }
     //end if else
     //--
     //--
     $err = '';
     //--
     if ((string) $do_send == 'yes') {
         //--
         if ((string) $this->method == 'mail') {
             //-- MAIL METHOD
             if ($this->debuglevel > 0) {
                 $this->log = 'SendMail :: DEBUG :: MAIL';
             }
             //end if
             //--
             if (SmartUnicode::mailsend($this->to, $this->prepare_subject($this->subject), '', $this->mime_message) != true) {
                 $err = 'Mail Method Failed !';
                 if ($this->debuglevel > 0) {
                     $this->log .= ' :: ' . $err;
                 }
                 //end if
             }
             //end if else
             //--
         } elseif ((string) $this->method == 'smtp') {
             //-- SMTP METHOD
             if ($this->debuglevel > 0) {
                 $this->log = 'SendMail :: DEBUG :: SMTP';
             }
             //end if
             //--
             $smtp = new SmartMailerSmtpClient();
             //--
             if ($this->debuglevel > 0) {
                 $smtp->debug = true;
                 $smtp->dbglevel = $this->debuglevel;
             } else {
                 $smtp->debug = false;
             }
             //end if
             //--
             $connect = $smtp->connect($this->smtp_helo, $this->smtp_server, $this->smtp_port, $this->smtp_ssl);
             //--
             if ($connect) {
                 //--
                 $login = 1;
                 // default
                 if ($this->smtp_login) {
                     $login = $smtp->login($this->smtp_user, $this->smtp_password);
                 }
                 //end if
                 //--
                 if ($login) {
                     //--
                     $vfy = $smtp->mail($this->from);
                     //--
                     if ($vfy) {
                         //--
                         $rcpt_to = $smtp->recipient($this->to);
                         //--
                         $rcpt_cc = 1;
                         if (is_array($this->cc)) {
                             for ($z = 0; $z < Smart::array_size($this->cc); $z++) {
                                 if (strlen($this->cc[$z]) > 0) {
                                     if ($rcpt_cc == 1) {
                                         $rcpt_cc = $smtp->recipient($this->cc[$z]);
                                     } else {
                                         break;
                                     }
                                     //end if
                                 }
                                 //end if
                             }
                             //end for
                         } elseif (strlen($this->cc) > 0) {
                             $rcpt_cc = $smtp->recipient((string) $this->cc);
                         }
                         //end if
                         //--
                         $rcpt_bcc = 1;
                         if (strlen($this->bcc) > 0) {
                             $rcpt_bcc = $smtp->recipient((string) $this->bcc);
                         }
                         //end if
                         //--
                         if ((string) $rcpt_to == '1' and (string) $rcpt_cc == '1' and (string) $rcpt_bcc == '1') {
                             //--
                             $sendresult = $smtp->data_send($this->mime_message);
                             //--
                             if ((string) $sendresult != '1') {
                                 $err = 'SMTP SEND-DATA :: ' . $smtp->error;
                             }
                             //end if
                             //--
                         } else {
                             //--
                             $err = 'SMTP RECIPIENT :: ' . $smtp->error;
                             //--
                         }
                         //end if
                         //--
                     } else {
                         //--
                         $err = 'SMTP MAIL :: ' . $smtp->error;
                         //--
                     }
                     //end if
                     //--
                 } else {
                     //--
                     $err = 'SMTP LOGIN :: ' . $smtp->error;
                     //--
                 }
                 //end if
                 //--
                 $smtp->noop();
                 //--
             } else {
                 //--
                 $err = 'SMTP CONNECT :: ' . $smtp->error;
                 //--
             }
             //end if
             //--
             if (strlen($err) > 0) {
                 $err = 'ERROR :: ' . $err;
             }
             //end if
             //--
             $smtp->quit();
             //--
             if ($this->debuglevel > 0) {
                 $this->log .= 'SMTP Log :: ' . $smtp->log;
             }
             //end if
             //--
         }
         //end else
         //--
     }
     //end if (send real)
     //--
     //--
     return $err;
     //--
 }
Пример #2
0
 /**
  * Does the MX Check of eMail / Domain
  * [PRIVATE]
  *
  * @param STRING $helo					:: SMTP HELO
  * @param STRING $email					:: eMail Address
  * @param NUMBER $y_smtp_port			:: SMTP Port (normal is '25')
  * @return STRING
  */
 public static function validate_mx_email_address($helo, $email, $y_smtp_port)
 {
     // will check all available MX servers from DNS
     //------------
     $out = 'notok';
     $msg = '';
     //------------
     //------------
     $tmp_arr = array();
     $tmp_arr = (array) explode('@', (string) $email);
     $domain = trim($tmp_arr[1]);
     $tmp_arr = array();
     //------------
     if (function_exists('getmxrr')) {
         @getmxrr(Smart::safe_validname($domain), $tmp_arr);
         // getmxrr is available also on Windows platforms since PHP 5.3
     } else {
         $msg .= 'WARNING: PHP getmxrr is not implemented on this platform ...';
     }
     //end if
     //------------
     if (Smart::array_size($tmp_arr) <= 0) {
         //-- ERR
         $msg .= 'WARNING: Invalid MX Records for Domain \'' . Smart::safe_validname($domain) . '\'' . "\n";
         //--
     } else {
         //--
         $msg .= 'List of available MX Servers for Domain \'' . Smart::safe_validname($domain) . '\':' . "\n";
         //--
         for ($m = 0; $m < Smart::array_size($tmp_arr); $m++) {
             //--
             $msg .= ' -> ' . $tmp_arr[$m] . "\n";
             //--
         }
         //end for
         //--
         $msg .= "\n";
         //--
     }
     //end if else
     //------------
     $msg .= '[Checking mail address: \'' . $email . '\']' . "\n";
     //------------
     for ($i = 0; $i < Smart::array_size($tmp_arr); $i++) {
         //--
         $domain = trim($tmp_arr[$i]);
         $domain_ip = @gethostbyname($domain);
         //--
         $msg .= 'Start MX checking for domain: \'' . $domain . '\' :: \'' . $domain_ip . '\' ... ' . "\n";
         //--
         $smtp = new SmartMailerSmtpClient();
         $smtp->timeout = 10;
         $smtp->debug = false;
         $smtp->connect($helo, $domain_ip, $y_smtp_port);
         $vfy = $smtp->mail($email);
         if ($vfy) {
             $vfy = $smtp->recipient($email);
         }
         //end if
         $smtp->quit();
         //--
         if ((string) $vfy == '1') {
             //--
             $out = 'ok';
             $msg .= '[done]' . "\n";
             //--
             break;
             //stop
             //--
         } else {
             //--
             $msg .= '[failed]' . "\n" . 'LOG: ' . "\n" . $smtp->log . "\n";
             //--
         }
         //end if else
         //--
         $msg .= $chk['message'] . "\n";
         //--
         if ($i >= 5) {
             break;
             // do not check more than 5 servers
         }
         //end if
         //--
     }
     //end for
     //------------
     //--
     return array('status' => $out, 'message' => $msg);
     //--
 }