require_once(APPPATH . '../third_party/PHPMailer/src/PHPMailer.php'); require_once(APPPATH . '../third_party/PHPMailer/src/SMTP.php'); require_once(APPPATH . '../third_party/PHPMailer/src/Exception.php'); // Load Composer's autoloader require 'application/helpers/vendor/autoload.php'; // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp.office365.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'xxxx.in'; // SMTP username $mail->Password = 'xxxx'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted $mail->Port = 587; // $mail->SMTPDebug = 1; //Recipients $mail->setFrom('xxxx.in', 'Mailer'); $mail->addAddress($data['mail'], 'Deepak Agarwal'); // Add a recipient // Attachments if($data['path'] != "" && $data['file'] != "") { $mail->addAttachment($data['path'],$data['file']); } // $mail->addAttachment('2.png'); // Add attachments // $mail->addAttachment('3.png'); // Add attachments //$mail->addAttachment('1.png', 'Certificate Logo.png'); // Optional name // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = $data['subject']; $mail->Body = $data['message']; $mail->AltBody = $data['message']; if(!$mail->send()) { // $this->CI->session->set_flashdata('msg', 'Message has not sent successfully.'); echo $mail->ErrorInfo; echo "Not send"; $this->CI->session->set_flashdata('msg',$mail->getMessage()); }else if(!$mail->ValidateAddress($data['mail'])){ $this->CI->session->set_flashdata('errmail','Mail Not Send..!'); } else{ $this->CI->session->set_flashdata('msg', 'Message has been sent successfully.'); } } catch (phpmailerException $e) { $this->CI->session->set_flashdata('errmail', $e->errorMessage()); //Pretty error messages from PHPMailer echo $e->errorMessage(); } catch (Exception $e) { $this->CI->session->set_flashdata('errmail', $e->getMessage()); //Boring error messages from anything else! echo $e->getMessage(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)