Skip to content

Instantly share code, notes, and snippets.

@Guley
Created November 27, 2018 04:57
Show Gist options
  • Save Guley/084b8b77e7abb3a740dd32ad51ec9d8c to your computer and use it in GitHub Desktop.
Save Guley/084b8b77e7abb3a740dd32ad51ec9d8c to your computer and use it in GitHub Desktop.
public function sendmail($maildata, $to, $subject, $attachments = [])
{
require_once(APPPATH.'third_party/PHPMailer/PHPMailerAutoload.php');
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
$mail->Host = 'SMTP_HOST';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->XMailer = 'YOUR_SITENAME';
$mail->Username = "YOUR_SMTP_USERNAME";
$mail->Password = "YOUR_SMTP_PASSWORD";
$mail->setFrom(EMAIL_FROM_ADDRESS, YOUR_SITENAME);
$recipients = explode(',', $to);
foreach($recipients as $email)
{
$mail->AddAddress($email);
}
$mail->Subject = $subject;
$mail->msgHTML($maildata);
if(!empty($attachments)){
foreach($attachments as $attachVal){
$mail->addAttachment($attachVal);
}
}
//send the message, check for errors
if(!$mail->send()) {
//echo $mail->ErrorInfo;exit;
$return = false;
} else {
$return = true;
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment