Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function get_data($smtp_conn)
- {
- $data="";
- while($str = fgets($smtp_conn,515))
- {
- $data .= $str;
- if(substr($str,3,1) == " ") { break; }
- }
- return $data;
- }
- function SendMail($config)
- {
- if(!isset($config['priority']))
- $config['priority']=3;
- $header="Date: ".date("D, j M Y G:i:s")." +0700rn";
- $header.="From: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode("{$config['from_title']}")))."?= <{$config['from']}>rn";
- $header.="X-Mailer: The Bat! (v3.99.3) Professionalrn";
- $header.="Reply-To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode("{$config['from_title']}")))."?= <{$config['from']}>rn";
- $header.="X-Priority: {$config['priority']}rn";
- $header.="Message-ID: <172562218.".date("YmjHis")."@microsoft.com>rn";
- $header.="To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($config['to_title'])))."?= <{$config['to']}>rn";
- $header.="Subject: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($config['subject'])))."?=rn";
- $header.="MIME-Version: 1.0rn";
- $header.="Content-Type: multipart/mixed; boundary="----------A4D921C2D10D7DB"rn";
- $attach=NULL;
- $code_file=NULL;
- if(isset($config['attach_file']))
- {
- if(file_exists($config['attach_file']))
- {
- $fp = fopen($config['attach_file'], "rb");
- $code_file = chunk_split(base64_encode(fread($fp, filesize($config['attach_file']))));
- fclose($fp);
- $attach.="------------A4D921C2D10D7DB
- Content-Type: application/octet-stream; name="".basename($config['attach_file']).""
- Content-transfer-encoding: base64
- Content-Disposition: attachment; filename="".basename($config['attach_file']).""
- {$code_file}";
- }
- }
- if(isset($config['attach_dir']))
- {
- $dir = $config['attach_dir'];
- if (is_dir($dir))
- if ($dh = opendir($dir))
- {
- while (($file = readdir($dh)) !== false)
- if($file!="." && $file!="..")
- {
- $fp = fopen($dir.$file, "rb");
- $code_file = chunk_split(base64_encode(fread($fp, filesize($dir.$file))));
- fclose($fp);
- $attach.="------------A4D921C2D10D7DB
- Content-Type: application/octet-stream; name="".basename($dir.$file).""
- Content-transfer-encoding: base64
- Content-Disposition: attachment; filename="".basename($dir.$file).""
- {$code_file}";
- }
- closedir($dh);
- }
- }
- if(isset($config['html_file']))
- {
- if(file_exists($config['html_file']))
- {
- $filename = $config['html_file'];
- $handle = fopen($filename, "r");
- $contents = fread($handle, filesize($filename));
- fclose($handle);
- $config['html'].=$contents;
- }
- }
- $text="------------A4D921C2D10D7DB
- Content-Type: text/html; charset=windows-1251
- Content-Transfer-Encoding: 8bit
- {$config['html']}
- {$attach}rn
- ------------A4D921C2D10D7DB--
- ";
- $smtp_conn = fsockopen($config['server'], $config['port'],$errno, $errstr, 10);
- if(!$smtp_conn) {print "Connect is fail"; fclose($smtp_conn); exit;}
- $data = get_data($smtp_conn);
- fputs($smtp_conn,"EHLO ".time()."rn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 250) {print "Command fail EHLO"; fclose($smtp_conn); exit;}
- if(isset($config['login']))
- {
- fputs($smtp_conn,"AUTH LOGINrn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 334) {print "Command fail AUTH LOGIN"; fclose($smtp_conn); exit;}
- fputs($smtp_conn,base64_encode($config['login'])."rn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 334) {print "Login is not exists"; fclose($smtp_conn); exit;}
- fputs($smtp_conn,base64_encode($config['password'])."rn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 235) {print "Password is not correct"; fclose($smtp_conn); exit;}
- }
- $size_msg=strlen($header."rn".$text);
- fputs($smtp_conn,"MAIL FROM:<{$config['from']}> SIZE=".$size_msg."rn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 250) {print "Command fail MAIL FROM"; fclose($smtp_conn); exit;}
- fputs($smtp_conn,"RCPT TO:<{$config['to']}>rn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 250 AND $code != 251) {print "Command fail RCPT TO"; fclose($smtp_conn); exit;}
- fputs($smtp_conn,"DATArn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 354) {print "Command fail DATA"; fclose($smtp_conn); exit;}
- fputs($smtp_conn,$header."rn".$text."rn.rn");
- $code = substr(get_data($smtp_conn),0,3);
- if($code != 250) {print "Send main error"; fclose($smtp_conn); exit;}
- fputs($smtp_conn,"QUITrn");
- fclose($smtp_conn);
- if(@$config['debug']=="on")
- {
- echo "<pre><code>";
- print_r($config);
- echo "</code></pre>";
- echo "Attach file:<br>{$attach}";
- }
- else
- echo "200: OK";
- }
- /*
- server - smtp.mail.ru
- port - 25
- login - barsukov.vv@mail.ru
- passowrd - *********
- from - admin@yandex.ru
- from_title - Администрация Яндекс.ру
- to - target@domain.net
- to_title - Target
- subject - Spam
- html - <div style='font-size:36pt;'>html</div>
- html_file - html/plain.html
- priority : важность
- 1 - высокая
- 3 - обычная(по умолчанию)
- 5 - низкая
- attach_file - image.jpg
- attach_dir - image/
- debug - De`жук(on)
- */
- SendMail(array("from"=>"admin@yandex.ru", "from_title"=>"Администрация Yandex.ru", "to"=>"barsukov.vv@mail.ru", "to_title"=>"Барсуков Владимир", "server"=>"mail-omsk.omsk.srsh.ru", "port"=>25, "subject"=>time(), "html"=>"html", "attach_file"=>"test/mazda.jpg", "attach_dir"=>"test/", "html_file"=>"test.html", "priority"=>"1", "debug"=>"on"));
- ?>
- <?php
- mail("to@somewhere.ru", "Subject", "message");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement