-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.php
52 lines (44 loc) · 1.48 KB
/
form.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
$servername = "localhost";
$username = "root";
$password = "";
$db = "wt";
$conn = mysqli_connect($servername, $username, $password, $db);
if ($conn) {
// echo"connection successfully";
$name = $_POST["name"];
$gmail = $_POST["email"];
$phone = $_POST["phone"];
$msg = $_POST["message"];
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; //your email
$mail->Password = 'iyxlmvxbyqvbevwc'; //your password
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('[email protected]'); //your gmail
$mail->addAddress($gmail);
$mail->isHTML(true);
$sql = "INSERT INTO `farmbook` (`name`, `gmail`, `phone`, `message`) VALUES ( '$name', '$gmail', '$phone', '$msg'); ";
$res = $conn->query($sql);
if ($res){
$mail->Subject = "AgriWell.com "; //$_POST["subject"]; // add subject \
$mail->Body = "<h1>Thanks for visiting</h1>"; //$_POST["message"]; // message
$mail->send();
echo "<script> alert('done');</script>";
header("Location: ./home.php");
} else {
echo "<script> alert('Error');</script>";
}
}
else{
die("Connection is not successful");
}
?>