forked from Krishneil1/Contact-Form-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
46 lines (42 loc) · 1.29 KB
/
contact.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
<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php';
$errors =[];
if(isset($_POST['name'],$_POST['email'],$_POST['message'])){
$fields=[
'name'=>$_POST['name'],
'email'=>$_POST['email'],
'message'=>$_POST['message']
];
foreach($fields as $field=>$data){
if(empty($data)){
$errors[]='The '.$field . ' field is required.';
}
}
if(empty($errors)){
$m=new PHPMailer;
$m->isSMTP();
$m->SMTPAuth=true;
$m->Host='smtp.gmail.com';
$m->Username='[email protected]';//replace with your email address
$m->Password='password';//replace with your password
$m->SMTPSecure='ssl';
$m->Port=465;
$m->isHTML();
$m->Subject ='Contact form Submitted';
$m->Body='From:'.$fields['name'].'('.$fields['email'].')<p>'.$fields['message'].'</p>';
$m->FromName='Contact';
$m->AddAddress('[email protected]','Some one');
if ($m->send()) {
header('Location:thanks.php');
die();
}else{
$errors[]="Sorry ,Could not send email.Try again later.";
}
}
}else{
$errors[]= 'Something went wrong';
}
$_SESSION['errors']=$errors;
$_SESSION['fields']=$fields;
header ('Location:index.php');