Mega Code Archive
Categories
/
Php
/
Email
Multi Type Mail
2, // 2 means accept all qualifiers:
"b"=>1, // 1 means accept the tag only:
"i"=>1, // note, recommend not allowing
as these can be used to call cgi-perl routines "a"=>2, "em"=>1, "br"=>1, "strong"=>1, "blockquote"=>1, "tt"=>1, "hr"=>1, "li"=>1, "ol"=>1, "ul"=>1 ); $str = stripslashes($str); $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<\\1>",$str); $str = eregi_replace("
]*)href=\"?([^\"]*)\"?([^>]*)>", "
", $str); $tmp = ""; while (eregi("<([^> ]*)([^>]*)>",$str,$reg)) { $i = strpos($str,$reg[0]); $l = strlen($reg[0]); if ($reg[1][0] == "/") $tag = strtolower(substr($reg[1],1)); else $tag = strtolower($reg[1]); if ($a = $approvedtags[$tag]) if ($reg[1][0] == "/") $tag = "$tag>"; elseif ($a == 1) $tag = "<$tag>"; else $tag = "<$tag " . $reg[2] . ">"; else $tag = ""; $tmp .= substr($str,0,$i) . $tag; $str = substr($str,$i+$l); } $str = $tmp . $str; // Squash PHP tags unconditionally $str = ereg_replace("<\?php","",$str); $str = ereg_replace("<\?","",$str); // Squash ASP tags unconditionally $str = ereg_replace("<%","",$str); return $str; } // end safeHTML // check if email address is valid function validate_email($val) { if($val != "") { $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/"; if(preg_match($pattern, $val)) return true; else return false; } else return false; } /* End local procedures */ if ($ishtml) { $txtmessage="This is a multi-part HTML-based message. Please use an HTML compliant email client."; $message=safeHTML($message); } else { // if its raw text, create a simple HTML version of it for HTML compatible email clients $txtmessage=$message; // save rawtext version //next line translates text into HTML using the PHP built-in function 'htmlentities' $message="
MultiMail Message
".htmlentities($message,ENT_QUOTES).""; $message=nl2br($message); //turn all hard coded newlines into HTML breaks } // If "to" list is prefixed with a pling then each recipient will be email'd separately so they cannot see other addresses if ($to[0]=="!") { $sendsep=1; $to=substr($to,1); } // build message headers // note use of \r\n (not just \n) in headers as this will work on all emailers $headers .= "From: $fromname <"."$fromemail".">\r\n"; if(!$sendsep && $cc) { $headers .= "Cc: $ccname <$cc>\r\n"; } if(!$sendsep && $bcc) { $headers .= "Bcc: $bccname <$bcc>\r\n"; } // create a MIME boundary strings $mime_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "====="; $related_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "====="; $alternative_boundary = "=====MULTIMAIL." . md5(uniqid(time())) . "====="; // add MIME data to the message headers $headers .= "MIME-Version:1.0\r\n"; $headers .= "Content-Type: multipart/mixed; \r\n\tboundary=\"$mime_boundary\";\r\n\r\n". "Content-Transfer-Encoding: 7bit\r\n". "This is a MIME-standard E-mail. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client."; // start building a MIME message // first part is always the message body // encode an alternative section for raw text & HTML $email_message = "--" . $mime_boundary . "\r\n". "Content-Type: multipart/related;\r\n\tboundary=\"$related_boundary\"\r\n\r\n". "--".$related_boundary."\r\n". "Content-Type: multipart/alternative;\r\n\tboundary=\"$alternative_boundary\"\r\n\r\n". // add raw text alternative as 7-bit text $email_message .= "--" . $alternative_boundary . "\r\n". "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n". "Content-Transfer-Encoding: 7bit\r\n\r\n". "$txtmessage\r\n\r\n"; // add HTML alternative part of message $email_message .= "--" . $alternative_boundary . "\r\n". "Content-Type:text/html;\r\n\tcharset=\"iso-8859-1\"\r\n" . "Content-Base: $HTTP_HOST\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" . $message . "\n\n"; $email_message .= "--" . $alternative_boundary . "--\r\n"; if ($attachmentloc!='' && filesize("$attachmentloc")>0) { $file = fopen("$attachmentloc",'rb'); $data = fread($file,filesize("$attachmentloc")); fclose($file); $data = chunk_split(base64_encode($data)); // note same as transfer coding in line below // add the MIME data $email_message .= "--" . $related_boundary . "\r\n". "Content-Type: application/octet-stream;\r\n\tname=\"$attfilename\"\r\n". "Content-Transfer-Encoding: base64\r\n". "Content-Disposition: attachment; \r\n\tfilename=\"$attfilename\"\r\n\r\n". $data . "\r\n". "\r\n--$related_boundary--\r\n"; } $email_message .= "--" . $mime_boundary . "--\r\n"; if (!validate_email($from_email)) $returnval=1; $formattedto = "$toname <".$toemail.">"; // send out the message if ($sendsep) { $allto = split(",", $to); for($x=0; $x
Multi-emailer
Please enter the following info
". "
". // note ENCTYPE - without this browser won't upload file to server just pass its name "
". "
To addr
". "
To name
". "
From addr
". "
From name
". "
Subject
". "
Message is in HTML? (select for yes)
". "
Message
". "
Attach file
". "
Send you a courtesy copy?
". "
Send you a blind courtesy copy?
". "
". "
". "
". "
". "
"; else { if ($cc_me=='on') {$cc=$from_addr; $cc_name=$from_name;} elseif ($bcc_me=='on') {$bcc=$from_addr; $bcc_name=$from_name;} if ($htmlformat=='on') $htmlon=1; else $htmlon=0; $i=strrpos($localfilename,"\\"); if (!$i) $i=strrpos($localfilename,"/"); $attfilename=substr($localfilename,($i+1)); if (strrpos($attach,"\\\\")||strrpos($attach,"\/\/"))$attach=stripslashes($attach); // stip out extra slashes if web client added them $result=multitypemail($msg,$htmlon,$subject,$to_name,$to_addr,$from_name,$from_addr,$attach,$attfilename,$cc,$cc_name,$bcc,$bcc_name); if ($result==1) print "I'm sorry, but the address '$to_addr' is not valid."; elseif ($result==2) print "I'm sorry, but the address '$from_addr' is not valid."; elseif ($result==3) print "I'm sorry, but the email was not sent."; else print "Email sent successfully.
"; print "
Please click
here
to send another message."; } ?>