Skip to content

Instantly share code, notes, and snippets.

@aslamdoctor
Created January 19, 2012 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslamdoctor/1640197 to your computer and use it in GitHub Desktop.
Save aslamdoctor/1640197 to your computer and use it in GitHub Desktop.
All in One PHP Mail Function
<?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