-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailhandler.php
91 lines (58 loc) · 3.41 KB
/
mailhandler.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';
header('Content-Type: application/json');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$firstname = $_POST["username"];
$email = $_POST["email"];
$message = $_POST["message"];
$subject = $_POST["subject"];
$mail = new PHPMailer(true);
$welcm_mail = new PHPMailer(true);
$usermailer ='[email protected]';
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.hostinger.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = $usermailer; //SMTP username
$mail->Password = 'Admin123@'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
$welcm_mail->isSMTP(); //Send using SMTP
$welcm_mail->Host = 'smtp.hostinger.com'; //Set the SMTP server to send through
$welcm_mail->SMTPAuth = true; //Enable SMTP authentication
$welcm_mail->Username = $usermailer; //SMTP username
$welcm_mail->Password = 'Admin123@'; //SMTP password
$welcm_mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$welcm_mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom($usermailer, 'ABHIMANYU SUPER-40'); // Admin mail
$mail->addAddress('[email protected]', $firstname); //Add a recipient
// $mail->addAddress('[email protected]'); //Name is optional
$mail->addReplyTo($usermailer, 'Information');
$welcm_mail->setFrom($usermailer, 'ABHIMANYU SUPER-40'); // user mail id
$welcm_mail->addAddress($email, $firstname); //Add a recipient
$welcm_mail->addReplyTo($usermailer, 'Information');
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = $subject;
$mail->Body = 'Name : '.$firstname.' <br> Message: '.$message.'<br>';
$mail->AltBody = "Name : ".$firstname." \n Message: ".$message."\n";
$welcm_mail->isHTML(true);
$welcm_mail->Subject = "Thank You For Your Enquiry";
$welcm_mail->Body = 'Hi '.$firstname.'<br> Thank You for your enquiry. Our Team will contact you soon. <br>';
$welcm_mail->AltBody = "Hi ".$firstname."\n Thank You for your enquiry. Our Team will contact you soon. \n";
$mail->send();
$welcm_mail->send();
header('Location: contact.php?msgresp=s');
} catch (Exception $e) {
// $errmsg = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
header('Location: contact.php?msgresp=f');
}
}
?>