-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendemail.php
71 lines (47 loc) · 1.98 KB
/
sendemail.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
<?php
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$to = 'stevie.zhang@mail.utoronto.ca'; //put your email here
$email_template = 'simple.html';
$subject = "SUBJECT";
$email = strip_tags($_POST['email']);
$phone = "";
$name = strip_tags($_POST['name']);
$message = nl2br( htmlspecialchars($_POST['message'], ENT_QUOTES) );
$result = array();
if(empty($name)){
$result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Error!</strong> Name is empty.' );
echo json_encode($result );
die;
}
if(empty($email)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> Email is empty.' );
echo json_encode($result );
die;
}
if(empty($message)){
$result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Error!</strong> Message body is empty.' );
echo json_encode($result );
die;
}
$headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templateTags = array(
'{{subject}}' => $subject,
'{{email}}'=>$email,
'{{message}}'=>$message,
'{{name}}'=>$name,
'{{phone}}'=>$phone
);
$templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$email_template);
$contents = strtr($templateContents, $templateTags);
if ( mail( $to, $subject, $contents, $headers ) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>Success!</strong> Mail Sent.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Cann\'t Send Mail.' );
}
echo json_encode( $result );
die;