-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.php
More file actions
64 lines (53 loc) · 2.18 KB
/
mail.php
File metadata and controls
64 lines (53 loc) · 2.18 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
<?php
define('admin_email','yuda8855@gmail.com'); // Change admin email here for example admin@yoursite.com
define('website_name','Locksmith'); // Change website name here for example yoursite.com
define('website_url', 'http://'.$_SERVER['HTTP_HOST']);
define('EMAIL_FROM', 'noreply@'.$_SERVER['HTTP_HOST']);
function strict_secure($str){
$str = strip_tags(trim($str));
return $str;
}
function sendEmail($to,$from,$subject,$message,$headname){
$headers="MIME-Version: 1.0" . "\r\n";
$headers.="Content-type: text/html; charset=utf-8" . "\r\n";
$headers.="From: ".$headname.'<'.$from.'>';
return mail ($to,$subject,$message,$headers);
}
if(isset($_POST['action']) && $_POST['action']=='submitform')
{
$N = array();
$N = $_POST['formInput'];
$path = $_SERVER['HTTP_REFERER'];
$admin_message = '<p>Dear Admin, Form submitted on '.website_url.'<br>Detail is as following.</p>';
foreach( $N as $label => $value ){
$admin_message .= '<p>'.ucwords($label).' : '.$value.'</p>';
}
$admin_message .= '<p>Form submitted on URL:<a href="'.$path.'">'.$path.'</a></p>';
$admin_message .= '<br><br>';
$admin_message .= 'Regards,<br />
'.website_name.'<br />
'.website_url.'
';
$user_message = 'Dear '.strict_secure($N['name']).',<br>';
$user_message .= 'Thank you submitting information. We will contact you soon.<br />';
$user_message .= 'Regards,<br />
'.website_name.'<br />
'.website_url.'
';
$admin_subject = 'Form Received From '.website_name;
$user_subject = 'Thank you - '.website_name;
$sendToAdmin = $sendToUsers = '';
$sendToAdmin = sendEmail(admin_email,EMAIL_FROM,$admin_subject,$admin_message,website_name);
if( isset( $N['email'] ) && ! empty( $N['email'] ) ){
$sendToUsers = sendEmail(strict_secure($N['email']),EMAIL_FROM,$user_subject,$user_message,website_name);
}
if($sendToAdmin || $sendToUsers)
{
$message ='Success::<div class="alert alert-success"><strong><i class="fa fa-info message-icon"></i><span>Message Sent Successfully.</span></strong></div>';
}else{
$message ='Error::<div class="alert alert-danger"><strong><i class="fa fa-info message-icon"></i><span>Something Went Wrong While Sending Message.</span></strong></div>';
}
echo $message;
}
exit();
?>