Skip to content

Instantly share code, notes, and snippets.

@rajeshvaya
Created April 14, 2015 10:29
Show Gist options
  • Save rajeshvaya/acb72f650e2e3af83c29 to your computer and use it in GitHub Desktop.
Save rajeshvaya/acb72f650e2e3af83c29 to your computer and use it in GitHub Desktop.
Sending email via PHP mailer lib
/**
*
* @param type $data
* @return boolean
*/
function send_email($data){
//include files
include_once('email/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1; // make this 1 to see debug messages
$mail->SMTPAuth = true;
$mail->Host = SMTP_HOST;
$mail->Port = 25;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SetFrom(SMTP_USERNAME,SMTP_USERNAME);
$mail->AddReplyTo(SMTP_USERNAME ,SMTP_USERNAME);
$mail->Subject = $data['subject'];
$mail->MsgHTML($data['body']);
$addresses = explode(",", $data['to_address']);
foreach($addresses as $address){
$mail->AddAddress(trim($address));
}
if($data['attachments']){
$attachments = explode(",", $data['attachments']);
foreach($attachments as $attachment){
$mail->AddAttachment(trim(DATA_FOLDER . $attachment));
}
}
if(!$mail->Send()){
return false;
}
else{
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment