from = $from; $email->subject = "Dados enviados pelo site"; $email->content = "Seguem os dados enviados pelo site\n"; foreach($_POST as $key => $value) { $value = htmlentities($value); $email->content .= "$key: $value\n
"; } if($email->send($to)) { header("Location: enviado.html"); } else echo "Erro enviando email. Tente novamente!"; } class Email { var $from; var $attachments = array(); var $headers = array(); var $content = ""; var $subject = ""; var $charset = "utf-8"; function attach($name = null, $data = null, $type='application/octet-stream') { if(!$name || !$data) return false; $this->attachments[] = array( 'name' => $name, 'type' => $type, 'data' => $data ); return true; } function attach_file($filepath) { if(!is_readable($filepath)) return false; return $this->attach(basename($filepath), file_get_contents($filepath)); } function send($to = null) { if(!$to) return false; if(empty($this->from)) $this->from = $_SERVER["SERVER_ADMIN"]; // Setup headers $mime_boundary = "==Multipart_Boundary_x".md5(time())."x"; // TODO : html/text switch $mail_headers = "Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\"\n" ."From: ".$this->from."\n" ."Return-Path: ".$this->from."\n" ."MIME-Version: 1.0\n"; // Additional headers foreach($this->headers as $key => $value) { $mail_headers .= "$key: $value\n"; } // TODO plaintext messages! $message = "This is a multi-part message in MIME format.\n\n" ."--{$mime_boundary}\n" ."Content-Type:text/html; charset=\"".$this->charset."\"\n" ."Content-Transfer-Encoding: 7bit\n\n" .$this->content ."\n\n"; foreach($this->attachments as $attachment) { $message .= "--{$mime_boundary}\n" ."Content-Type: {$attachment['type']};\n" ." name=\"{$attachment['name']}\"\n" ."Content-Transfer-Encoding: base64\n\n" .chunk_split(base64_encode($attachment['data'])); } return(@mail($to, $this->subject, $message, $mail_headers, "-f".$this->from)); } } ?>