Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function clean4email($s){
- $t = Array("\r","\n","\t","%0A","%0D","%08","%09",'cc:','bcc:');
- return str_ireplace($t, '',$s);
- }
- function email($to,$from, $subject,$message,$uploadFiles=Array()){
- $to = clean4email($to);
- $from = clean4email($from);
- $subject = clean4email($subject);
- $uid = uniqid(time(),true);
- $header = "From: {$from}\r\n";
- $header .= "Reply-To: {$from}\r\n";
- $header .= "MIME-Version: 1.0\r\n";
- $header .= "Content-Type: multipart/mixed; boundary=\"{$uid}\"\r\n\r\n";
- $header .= "This is a multi-part message in MIME format.\r\n";
- $header .= "--{$uid}\r\n";
- $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
- $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
- $header .= "{$message}\r\n\r\n";
- // File Attachment
- foreach($uploadFiles as $file){
- $filelocal = $file['tmp_name'];
- $mime = $file['type'];
- $filename = $file['name'];
- if(file_exists($filelocal)){
- $fh = @fopen($filelocal, "r");
- $content = chunk_split( base64_encode( fread($fh, filesize( $filelocal ))));
- @fclose($fh);
- $mime = (($mime !== false && strlen($mime) > 0)? $mime : 'application/octet-stream');
- $header .= "--{$uid}\r\n";
- $header .= "Content-Type: {$mime}; name=\"{$filename}\"\r\n";
- $header .= "Content-Transfer-Encoding: base64\r\n";
- $header .= "Content-Disposition: attachment; filename=\"{$filename}\"\r\n\r\n";
- $header .= $content . "\r\n\r\n";
- }
- }
- $header .= "--".$uid."--";
- return mail($to, $subject, "", $header);
- }
- $email = $_POST['email'];
- $from = $_POST['name'] . ' <' . $email . '>';
- // $recipient = "blanger@hawaii.edu";
- $recipient = "gitlez@gmx.com";
- $subject = "New Project Request from 2DadsDB.com";
- $formItems = Array('name','address','phone','email','timeline','message');
- $formcontent = "New Project Request From 2DadsDB.com" . PHP_EOL . PHP_EOL;
- foreach($formItems as $item){
- $formcontent .= ucwords($item) . ': ' . $_POST[$item] . PHP_EOL;
- }
- if( email($recipient, $from, $subject, $formcontent,$_FILES) ){
- echo '<h1>Success</h1>';
- echo 'Thank You! <a href="contactus.html">Go Back</a>';
- }else{
- echo '<h1>Error</h1>';
- }
- ?>
Add Comment
Please, Sign In to add comment