當前位置: 首頁>>代碼示例>>PHP>>正文


PHP mail::type方法代碼示例

本文整理匯總了PHP中mail::type方法的典型用法代碼示例。如果您正苦於以下問題:PHP mail::type方法的具體用法?PHP mail::type怎麽用?PHP mail::type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mail的用法示例。


在下文中一共展示了mail::type方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: smtp

 function smtp($to, $semi_rand)
 {
     $header = "Date: " . date("D, j M Y G:i:s") . " +0700\r\n";
     if (self::$from_name) {
         $header .= "From: =?utf-8?Q?" . str_replace("+", "_", str_replace("%", "=", urlencode(self::$from_name))) . "?= <" . self::$from_email . ">\r\n";
     } else {
         $header .= "From: " . self::$from_email . "\r\n";
     }
     //$header .= "X-Mailer: The Bat! (v3.99.3) Professional\r\n";
     //$header .= "Reply-To: =?utf-8?Q?".str_replace("+","_",str_replace("%","=",urlencode('Максим')))."?= <lessio@lessio.ru>\r\n";
     if (self::$html) {
         $text = self::$html;
     } else {
         if (self::$text) {
             self::$type = 'plain';
             $text = self::$text;
         }
     }
     $header .= "X-Priority: 3 (Normal)\r\n";
     $header .= "Message-ID: <172562218." . date("YmjHis") . ">\r\n";
     $header .= "To: " . $to . "\r\n";
     $header .= "Subject: =?utf-8?Q?" . str_replace("+", "_", str_replace("%", "=", urlencode(self::$subject))) . "?=\r\n";
     $header .= "MIME-Version: 1.0\r\n";
     if (self::$file) {
         $header .= "Content-Type: multipart/mixed; boundary=\"----------{$semi_rand}\"\r\n";
         $file = self::$file;
         $fileatttype = self::MIMEType($file);
         $fileattname = basename($file);
         $fp = fopen($file, "rb");
         $code_file = chunk_split(base64_encode(fread($fp, filesize($file))));
         fclose($fp);
         $text = "------------{$semi_rand}\r\nContent-Type: text/html; charset=\"utf-8\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n" . $text . "\r\n\r\n------------{$semi_rand}\r\nContent-Type: {$fileatttype}; name=\"{$fileattname}\"\r\nContent-transfer-encoding: base64\r\nContent-Disposition: attachment; filename=\"{$fileattname}\"\r\n\r\n" . $code_file . "\r\n------------{$semi_rand}--\r\n";
     } else {
         $header .= "Content-Type: text/" . self::$type . "; charset=utf-8\r\n";
         $header .= "Content-Transfer-Encoding: 8bit\r\n";
     }
     $smtp_conn = fsockopen(self::$smtp_host, self::$smtp_port, $errno, $errstr, 10);
     if (!$smtp_conn) {
         print "соединение с серверов не прошло";
         fclose($smtp_conn);
         exit;
     }
     $data = self::get_data($smtp_conn);
     fputs($smtp_conn, "EHLO " . self::$smtp_host . "\r\n");
     $code = substr(self::get_data($smtp_conn), 0, 3);
     if ($code != 250) {
         print "ошибка приветсвия EHLO";
         fclose($smtp_conn);
         exit;
     }
     /*
     auth
     
     fputs($smtp_conn,"AUTH LOGIN\r\n");
     $code = substr(get_data($smtp_conn),0,3);
     if($code != 334) {print "сервер не разрешил начать авторизацию"; fclose($smtp_conn); exit;}
     
     fputs($smtp_conn,base64_encode("login")."\r\n");
     $code = substr(get_data($smtp_conn),0,3);
     if($code != 334) {print "ошибка доступа к такому юзеру"; fclose($smtp_conn); exit;}
     
     fputs($smtp_conn,base64_encode("password")."\r\n");
     $code = substr(get_data($smtp_conn),0,3);
     if($code != 235) {print "не правильный пароль"; fclose($smtp_conn); exit;}
     */
     fputs($smtp_conn, "MAIL FROM:" . self::$from_email . "\r\n");
     $code = substr(self::get_data($smtp_conn), 0, 3);
     if ($code != 250) {
         print "сервер отказал в команде MAIL FROM";
         fclose($smtp_conn);
         exit;
     }
     fputs($smtp_conn, "RCPT TO:" . $to . "\r\n");
     $code = substr(self::get_data($smtp_conn), 0, 3);
     if ($code != 250 and $code != 251) {
         print "Сервер не принял команду RCPT TO";
         fclose($smtp_conn);
         exit;
     }
     fputs($smtp_conn, "DATA\r\n");
     $code = substr(self::get_data($smtp_conn), 0, 3);
     if ($code != 354) {
         print "сервер не принял DATA";
         fclose($smtp_conn);
         exit;
     }
     fputs($smtp_conn, $header . "\r\n" . $text . "\r\n.\r\n");
     $code = substr(self::get_data($smtp_conn), 0, 3);
     if ($code != 250) {
         print "ошибка отправки письма";
         fclose($smtp_conn);
         exit;
     }
     fputs($smtp_conn, "QUIT\r\n");
     fclose($smtp_conn);
     self::clear();
     return true;
 }
開發者ID:rigidus,項目名稱:ea,代碼行數:98,代碼來源:mail.php


注:本文中的mail::type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。