-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.php
More file actions
39 lines (32 loc) · 1.06 KB
/
mail.php
File metadata and controls
39 lines (32 loc) · 1.06 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
<?php
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
require 'phpmailer/Exception.php';
$title = "New message";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = "New Message";
$body = "Name: $name\nEmail: $email\nMessage:\n$message";
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true;
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
$mail->Username = 'user@example.com'; //SMTP username
$mail->Password = 'secret'; //SMTP password
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('from@example.com', $title);
$mail->addAddress('youraddress@mail.me');
$mail->isHTML(true);
$mail->Subject = $title;
$mail->Body = $body;
$mail->send();
http_response_code(200);
echo "Message sent successfully!";
} catch (Exception $e) {
http_response_code(500);
echo "Failed to send the message. Try again";
}