forked from Vimall03/Alimento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
47 lines (39 loc) · 1.69 KB
/
contact.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
// If you have changed the path, then update the path here too
require 'C:\xampp\htdocs\Alimento\phpmailer\Exception.php';
require 'C:\xampp\htdocs\Alimento\phpmailer\PHPMailer.php';
require 'C:\xampp\htdocs\Alimento\phpmailer\SMTP.php';
//dont change the below use conditions
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
$mail = new PHPMailer(true);
try {
// SMTP Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // Your email address
$mail->Password = 'pdiiozxxjwetwvtw'; // Your email app password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Recipients
$mail->setFrom($email, $name); // From the form sender's email and name
$mail->addAddress('[email protected]'); // Your email to receive the message
// Email content
$mail->isHTML(true);
$mail->Subject = 'New Message from Alimento Contact Form';
$mail->Body = nl2br("Name: $name\nEmail: $email\nMessage:\n$message");
$mail->AltBody = "Name: $name\nEmail: $email\nMessage:\n$message"; // Plain message edit this for custom message
// Send email
$mail->send();
header('Location: index.php?success=true');
exit();
//echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}