Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mail
- {
- private $smtp_settings=array();
- private $trenner;
- private $use_html;
- private $files=array();
- private $header="";
- public function __construct($from_name,$from_mail, $use_html=true,$reply="")
- {
- $this->use_html=$use_html;
- $this->smtp_settings=array("from"=> $from_name."<".$from_mail.">");
- $this->trenner = md5(uniqid(time()));
- $this->header = "From: $from_name <$from_mail>\n";
- if($reply=="")
- $reply=$from_mail;
- $this->header .= "Reply-To: ".$from_name." <".$reply.">\n";
- $this->header .= "MIME-Version: 1.0";
- $this->header .= "\n";
- $this->header .= "Content-Type: multipart/mixed; boundary=".$this->trenner;
- $this->header .= "\n\n";
- $this->header .= "This is a multi-part message in MIME format";
- $this->header .= "\n";
- $this->header .= "--".$this->trenner;
- $this->header .= "\n";
- if($use_html)
- $this->header .= "Content-Type: text/html";
- else
- $this->header .= "Content-Type: text/plain";
- $this->header .= "\n";
- $this->header .= "Content-Transfer-Encoding: 8bit";
- $this->header .= "\n\n";
- }
- public function text($text)
- {
- if(!preg_match("/(.*)\n/m",$text))
- $text=$text."\n";
- if($this->use_html)
- {
- $text=htmlspecialchars($text);
- $text=str_replace(array("\r\n","\n","\r"),"<br>",$text);
- }
- $this->header.=$text;
- }
- function html($text)
- {
- if(!$this->use_html)
- {
- $text=str_replace(array("\r\n","\n","\r"),"",$text);
- $text=str_replace(array("<br>","</p>"),"\n",$text);
- $text=preg_replace("/<(.*?)>/i","",$text);
- if(!preg_match("/(.*)\n/m",$text))
- $text=$text."\n";
- $this->header.=$text;
- }
- else
- {
- if(!preg_match("/(.*)(<br>|<\/p>)/m",$text))
- $text=$text."<br>";
- $this->header.=$text;
- }
- }
- public function file($file_name,$file_path)
- {
- if(isset($this->files[$file_name])) return false;
- $this->files[$file_name]=$file_path;
- }
- public function send($empfaenger,$betreff)
- {
- $this->header .= "\n";
- foreach($this->files as $name => $path)
- {
- $Dateiinhalt = fread(fopen($path, "r"), filesize($path));
- $this->header .= "--".$this->trenner;
- $this->header .= "\n";
- $this->header .= "Content-Type: application/octet-stream; name=$name";
- $this->header .= "\n";
- $this->header .= "Content-Transfer-Encoding: base64";
- $this->header .= "\n";
- $this->header .= "Content-Disposition: attachment; filename=$name";
- $this->header .= "\n\n";
- $this->header .= chunk_split(base64_encode($Dateiinhalt));
- $this->header .= "\n";
- }
- $this->header .= "--".$this->trenner."--";
- if(isset($this->smtp_settings["host"]))
- $this->smtp_mail($empfaenger,$betreff);
- else
- mail ($empfaenger,$betreff,"",$this->header);
- }
- public function set_smtp($host,$username,$password)
- {
- $this->smtp_settings["host"]=$host;
- $this->smtp_settings["username"]=$username;
- $this->smtp_settings["password"]=$password;
- }
- function smtp_mail($to,$subject)
- {
- $smtp_server = $this->smtp_settings["host"];
- $port = 25;
- $mydomain = "Domain";
- $username = $this->smtp_settings["username"];
- $password = $this->smtp_settings["password"];
- $sender = $this->smtp_settings["from"];
- $recipient = $to;
- $subject = $subject;
- $content = $this->header;
- // Initiate connection with the SMTP server
- $handle = fsockopen($smtp_server,$port,$errno,$errstr);
- if(!$handle)
- echo "Konnte Verbindung nicht aufbauen: Fehler($errno): $errstr<br>\r\n";
- fputs($handle, "EHLO ".$mydomain."\n");
- // SMTP authorization
- fputs($handle, "AUTH LOGIN\n");
- fputs($handle, base64_encode($username)."\n");
- fputs($handle, base64_encode($password)."\n");
- // Send out the e-mail
- fputs($handle, "MAIL FROM: ".$sender."\n");
- fputs($handle, "RCPT TO: ".$recipient."\n");
- fputs($handle, "DATA\n");
- fputs($handle, "To: ".$recipient."\n");
- fputs($handle, "Subject: ".$subject ."\n");
- fputs($handle, $content."\n");
- fputs($handle, ".\n");
- // Close connection to SMTP server
- fputs($handle, "QUIT\n");
- $responce_codes=array(220,250,250,250,250,250,250,250,334,334,235,250,250,354,250,221);
- for($i=0;$i<count($responce_codes);$i++)
- {
- $responce=fgets($handle);
- if (substr($responce, 0, 3) != $responce_codes[$i])
- {
- if(substr($responce, 0, 3) != $responce_codes[($i+1)])
- echo "Probleme beim Versand: $responce<br>\r\n";
- else
- $i++;
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement