-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact-with-phpMailer.php
More file actions
122 lines (112 loc) · 4.1 KB
/
Copy pathcontact-with-phpMailer.php
File metadata and controls
122 lines (112 loc) · 4.1 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
// error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); // run all reporting errors except E_NOTICE and E_WARNING
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// require 'vendor/phpmailer/phpmailer/src/Exception.php';
// require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
// require 'vendor/phpmailer/phpmailer/src/SMTP.php';
//Load composer's autoloader
require_once 'vendor/autoload.php';
// check data coming from method post
if ($_SERVER['REQUEST_METHOD'] == "POST"){
// Variables
$user = filter_var($_POST['user'], FILTER_SANITIZE_STRING);
$mail_user = filter_var($_POST['mails'], FILTER_SANITIZE_EMAIL);
$phone = filter_var($_POST['phoneN'], FILTER_SANITIZE_NUMBER_INT);
$msg = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
$recapcha_response = $_POST['recapacha'];
$sRecaptcha = false;
$body_msg = "
<center>
<div style = '
background-color:#f0f0f0;
height:auto;
padding: 13px 40px 13px 40px ;
width:auto;
'>
<div style = '
border-right:#9eae9e 3px solid;
border-left:#9eae9e 3px solid;
'>
<div style = '
padding-top:15px;
padding-bottom:15px;
background-color:#9eae9e;
width:100%;
'>W e l c o m e, abdelrazek.dx.am</div>
<div style = '
width:100%;
background-color:#fefefe;
padding:30px 0 30px 0;
'>$msg</div>
<div style = '
color:white;
width:100%;
background-color:#9eae9e;
padding:15px 0 15px 0;
'>All Rights Reserved 2018</div>
</div>
</div>
</center>
";
$url = "https://www.google.com/recaptcha/api/siteverify";
$privatekey = "6LfyLWkUAAAAAK0BJGl-u5Oai9FhDyUST8hvSRRL";
$response = file_get_contents($url."?secret=".$privatekey."&response=".$recapcha_response);
$data = json_decode($response);
if (isset($data -> success) AND $data -> success == true){
$sRecaptcha = true;
}
if (strlen($recapcha_response) > 0){
$sRecaptcha = true;
}
// Error in inputs fields
$formErrors = array();
if (strlen("$user") <= 3){
$formErrors[] = "User name not allow char less than 3";
}
// Validation Number not String and not less than 11
if (strlen("$msg") <= 15){
$formErrors[] = "message not allow char less than 15";
}
if (!is_numeric($phone)){
$formErrors[] = " - phone should be Number ";
}else{
if (strlen("$phone") > 16 ){
$formErrors[] = "Phone should less than 16 Number ...";
}
}
if (!$sRecaptcha){
$formErrors[] = "Fail Recaptcha..";
}
// Send mail by phpMailler
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
$mail->SMTPDebug =0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com;smtp2.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username ''
$mail->Password = ''; // SMTP password ''
$mail->SMTPSecure = "tls"; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
//Recipients
$mail->addAddress('abdelrazek.n4@gmail.com');
$mail->addReplyTo($mail_user, $user);
$mail->setFrom("abdelrazek.n4@gmail.com", "abdelrazek");
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "My Work";
$mail->Body = $body_msg;
$mail->AltBody = "last body";
$successM = $mail->send();
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
if (isset($successM) && $successM){
echo 1;
}else{
echo (json_encode($formErrors));
}
}
?>