-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactUsAction.php
101 lines (68 loc) · 2.45 KB
/
ContactUsAction.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
92
93
94
95
96
97
98
99
100
101
<?php
require_once __DIR__.'/Bootstrap.php';
/* Namespace alias. */
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
/* Include the Composer generated autoload.php file. */
require './vendor/autoload.php';
/* Create a new PHPMailer object. Passing TRUE to the constructor enables exceptions. */
$mail = new PHPMailer(TRUE);
//setting variables from user input data from form
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$message = $_POST['message'];
//contructing email assets
$recipient = "[email protected]";
$recipientName = "Ta' Pinu Restaurant";
$subject = "Contact Form";
$mailheader = "From: $name $surname $email \r\n";
$formcontent="To: $recipientName \n\nMessage: $message \n\n$mailheader";
/* Open the try/catch block. */
try {
/* Set the mail sender. */
$mail->setFrom($email, "$name $surname");
/* Add a recipient. */
$mail->addAddress($recipient, $recipientName);
/* Set the subject. */
$mail->Subject = $subject;
//Set the mail message body.
$mail->Body = $formcontent;
/* SMTP parameters. */
//Tells PHPMailer to use SMTP.
$mail->isSMTP();
/*
To test if email has been sent or not
$mail->SMTPDebug = 2;
*/
// SMTP server address.
$mail->Host = 'smtp.gmail.com';//'smtp.empire.com';
// Use SMTP authentication.
$mail->SMTPAuth = TRUE;
//Set the encryption system.
$mail->SMTPSecure = 'tls';
//SMTP authentication username.
$mail->Username = '[email protected]';
//SMTP authentication password.
$mail->Password = 'icqdjutisaassnyl';
//Set the SMTP port.
$mail->Port = 587;
//Finally send the mail.
$mail->send();
$isSent = TRUE;
}catch (Exception $e){
// PHPMailer exception.
echo $e-> errorMessage();
$isSent = FALSE;
}catch (\Exception $e){
// PHP exception
echo $e-> errorMessage();
$isSent = FALSE;
}
//renders the correct page according to wheter the email was sent succesfully or not
if($isSent==TRUE){
echo $twig->render('/templates/emailSent.html');
}else{
echo $twig->render('/templates/emailError.html', ['error' => $e]);
}
?>