· 8 years ago · Mar 21, 2018, 10:16 PM
1//Import PHPMailer classes into the global namespace
2
3 use PHPMailer\PHPMailer\PHPMailer;
4 use PHPMailer\PHPMailer\Exception;
5 require_once 'vendor/autoload.php';
6 $mail = new PHPMailer(true);
7
8 $mail->isSMTP();
9 $mail->Host = 'smtp.googlemail.com'; //gmail SMTP server
10 $mail->SMTPAuth = true;
11 $mail->Username = '*****@gmail.com'; //username
12 $mail->Password = '********'; //password
13 $mail->SMTPSecure = 'ssl';
14 $mail->Port = 465; //SMTP port
15
16 $mail->setFrom('noreply@artisansweb.net', 'Artisans Web');
17 $mail->addAddress('******@gmail.com', 'User Name');
18
19 $mail->isHTML(true);
20
21 $mail->Subject = 'Email subject';
22 $mail->Body = 'Email Body';
23
24 if (!$mail->send()) {
25 echo 'Message could not be sent.';
26 echo 'Mailer Error: ' . $mail->ErrorInfo;
27 } else {
28 echo 'Message has been sent';
29 }