-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendMail.php
51 lines (37 loc) · 1.18 KB
/
sendMail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
//import PHPMailer classes
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require "PHPMailer/vendor/autoload.php";
$mail = new PHPMailer(true);
$recipientArr = array('');
$myUsername = //account username;
$myPassword = //account password;
$bodyHtml = //Body of E-mail;
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.live.com' //for outlook; //For Gmail: smtp.gmail.com
$mail->SMTPAuth = true;
$mail->Username = $myUsername;
$mail->Password = $myPassword;
$mail->SMTPSecure = 'tls';
$mail->Port = '587';
//Recepient
$mail->setFrom($myUsername, //Sent name);
if (!empty($recipientArr)) { //have mutiple recepients
foreach ($recipientArr AS $eachAddress) {
$mail->addAddress($eachAddress);
} }
$mail->addReplyTo($myUsername);
//Content of Mail
$mail->isHTML(true);
$mail->Subject = //subject of E-mail;
$mail->Body = $bodyHtml;
//send mail
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>