Created
January 19, 2012 14:09
-
-
Save aslamdoctor/1640197 to your computer and use it in GitHub Desktop.
All in One PHP Mail Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function send_mail($from, $from_name, $to, $to_name, $subject, $body, $attachment="") | |
{ | |
include_once("phpmailer.class.php"); | |
$mail = new PHPMailer(); | |
$mail->From = $from; | |
$mail->FromName = $from_name; | |
$mail->Subject = $subject; | |
$search = array( | |
'@<script[^>]*?>.*?</script>@si', // Strip out javascript | |
'@<[/!]*?[^<>]*?>@si', // Strip out HTML tags | |
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly | |
'@<![sS]*?--[ tnr]*>@' // Strip multi-line comments | |
); | |
$altBody= preg_replace($search, '', $body); | |
$mail->AltBody = $altBody; | |
$mail->MsgHTML($body); $mail->AddAddress($to, $to_name); | |
if(!empty($attachment)) { | |
$mail->AddAttachment($attachment); | |
} | |
@$mail->Send(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment