· 7 years ago · Sep 08, 2018, 08:14 PM
1<?php
2require_once('PHPMailer/PHPMailerAutoload.php');
3class Mail {
4 public static function sendMail($subject, $body, $address) {
5 try
6 {
7 $mail = new PHPMailer();
8 $mail->IsSMTP();
9 //$mail->SMTPDebug = 4;
10 $mail->SMTPAuth = true;
11 $mail->SMTPSecure = 'ssl';
12 $mail->SMTPOptions = array
13 (
14 'ssl' => array
15 (
16 'verify_peer' => false,
17 'verify_peer_name' => false,
18 'allow_self_signed' => true
19 )
20 );
21 $mail->Host = "smtp.gmail.com";
22 $mail->Port = 465;
23 $mail->IsHTML(true);
24 $mail->Username = "**********@gmail.com";
25 $mail->Password = "*******";
26 $mail->SetFrom("*************@gmail.com");
27 $mail->Subject = $subject;
28 $mail->Body = $body;
29 $mail->AddAddress($address);
30 if(!$mail->Send())
31 {
32 echo "Mailer Error: " . $mail->ErrorInfo;
33 }
34
35
36 }
37 catch (phpmailerException $e)
38 {
39 $errors[] = $e->errorMessage();
40 }
41 catch (Exception $e)
42 {
43 $errors[] = $e->getMessage();
44 }
45 }
46 }