Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Add Comment
Please, Sign In to add comment