-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmsg.php
77 lines (54 loc) · 2.26 KB
/
sendmsg.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
<?php
//Open a new connection to the MySQL server
$mysqli = new mysqli($your_servername, $your_username, $your_password, $your_dbname);
//Output any connection error
if ($mysqli->connect_error) {
die('Error : (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
$fname = mysqli_real_escape_string($mysqli, $_POST['fname']);
$email = mysqli_real_escape_string($mysqli, $_POST['email']);
$message= mysqli_real_escape_string($mysqli, $_POST['message']);
$email2 = "";
$subject = "Test Message";
if (strlen($fname) > 50) {
echo 'fname_long';
} elseif (strlen($fname) < 2) {
echo 'fname_short';
} elseif (strlen($email) > 50) {
echo 'email_long';
} elseif (strlen($email) < 2) {
echo 'email_short';
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
echo 'eformat';
} elseif (strlen($message) > 500) {
echo 'message_long';
} elseif (strlen($message) < 3) {
echo 'message_short';
} else {
//MAILER
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
// $mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'your_email'; // SMTP username
$mail->Password = 'your_email_password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->AddReplyTo($email);
$mail->From = $email2;
$mail->FromName = $fname;
$mail->addAddress('your_reciptent', 'Admin'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = '';
$mail->Body = "Message from - $email <br> Message - $message";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'true';
}
}
?>