Today I am going to show you my own created php Function for easy Emailing.
I have used PHPMailer Class file for it, which you can grab from here. I have made all the Emailing featured in PHP very easy to use by just calling a Single line function.
Here is the Code which you can grab for your own use
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();
}
Arguments :
$from = Email Address of the person to show in “From” field
$from_name = Name of the person to show in “From” field
$to = Email address of the person to whom email will be sent
$to_name = Name of the person to whom email will be sent
$subject = Subject of the Email
$body = Email message text (html/plain text)
$attachment = Path to the Attachment file (optional)
Hope you all find this useful in your coding process
Terrific, this data is exactly what I was searching for. I am in fact thankful to this topic because it truly gives beneficial information. Very well written blog. I look transmit to looking more. This blog is bookmarked! I admittedly love the stuff you have put here.