-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail.php
47 lines (40 loc) · 1.22 KB
/
mail.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
<?php
////////////////////////
// PHPMailer example
////////////////////////
// Login credentials
$server_smtp = "smtp.hostinger.com";
$server_imap = "imap.hostinger.com";
$email_account = "[email protected]";
$email_password = "Password123";
// Recipient
$recipient = "[email protected]";
// Stop making changes below this line
use PHPMailer\PHPMailer\PHPMailer;
require "./phpmailer/autoload.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = $server_smtp;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Username = $email_account;
$mail->Password = $email_password;
$mail->setFrom($email_account, "");
$mail->addReplyTo($email_account, "");
$mail->addAddress($recipient, "");
$mail->Subject = "This means that emails work fine.";
$mail->msgHTML("<h1>Incoming message to Houston</h1>");
if (!$mail->send()) {
echo "error: ".$mail->ErrorInfo;
} else {
echo "Message sent";
if(!empty($server_imap)) {
// Add the message to the IMAP.Sent mailbox
$mail_string = $mail->getSentMIMEMessage();
$imap_stream = imap_open("{".$server_imap."}", $email_account, $email_password);
imap_append($imap_stream, "{".$server_imap."}INBOX.Sent", $mail_string);
}
}