Repository navigation
Expand file tree
/
Copy pathtest-mail.php
More file actions
51 lines (40 loc) · 2.2 KB
/
Copy pathtest-mail.php
File metadata and controls
51 lines (40 loc) · 2.2 KB
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
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once('scripts/dependencies/third-party/PHPMailer/src/PHPMailer.php');
require_once('scripts/dependencies/third-party/PHPMailer/src/SMTP.php');
require_once('scripts/dependencies/third-party/PHPMailer/src/Exception.php');
require_once('.credentials.php');
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = $_MAIL['location']; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = $_MAIL['username']; //SMTP username
$mail->Password = $_MAIL['password']; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('no-reply-sems@brookes.ac.uk', 'SEMS');
$mail->addAddress('bywater30@gmail.com', 'louise'); //Add a recipient
// $mail->addAddress('ellen@example.com'); //Name is optional
// $mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'This is a test subject';
$mail->Body = 'Please work... <b>is this bold?</b>';
$mail->AltBody = 'If you have an old email client that doesn\'t support HTML, you should see this.';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>