-
Notifications
You must be signed in to change notification settings - Fork 2
/
mail.php
169 lines (127 loc) · 4.24 KB
/
mail.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
header('Content-type:application/json');
if(isset($_POST['email']) && !empty($_POST['email']) && isset($_POST['phone']) &&
!empty($_POST['phone']) && isset($_POST['fname']) && !empty($_POST['fname']) &&
isset($_POST['company']) && !empty($_POST['company']) && isset($_POST['list']) && !empty($_POST['list'])
){
$email=$_POST['email'];
$phone=$_POST['phone'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$company=$_POST['company'];
$list=$_POST['list'];
if (isset($_FILES['attachment'])){
//$check = getimagesize($_FILES["attachment"]["tmp_name"]);
$tmp_file=$_FILES['attachment']['tmp_name'];
$attachment =chunk_split(base64_encode(file_get_contents($tmp_file))); // Set your file path here
}
else{
$attachment="";
}
sendEmail($email, $phone, $fname, $lname, $company, $list, $attachment);
}
else{
//please provide email
echo json_encode(array(
'status' => 'error',
'message' => 'Please fill all fields'
));
exit();
}
function sendEmail($email, $phone, $fname, $lname, $company, $list, $attachment){
//$to='info@rindgroup.com';
$to='nnyanziian@gmail.com';
//$message = "Request Quote from ".$fname." ".$lname.", ".$email.", ".$phone.", ".$company.", ".$list;
$message='<!DOCTYPE html><head><meta charset="UTF-8"><title>RindPharma - Request Mail from:'.$fname." ".$lname.'</title>
<style>
*{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; margin:0; padding:0;}
img { width:150px; margin:10px auto; display:block; }
body{ border:3px solid #ad1c17; font-family: "Source Sans Pro", Arial, Helvetica, sans-serif;
font-size: 20px;
line-height: 32px;
font-weight: 300;
color: rgba(0, 0, 0 , 0.5);
background: #f7f7f7;
text-rendering: optimizeLegibility;
vertical-align: baseline;
}
.group{
width:80%;
display:block;
margin:10px auto;
background-color:#618739;
padding:5px;
overflow:auto;
}
.group-light{
width:80%;
display:block;
margin:10px auto;
background-color:#fff;
padding:5px;
overflow:auto;
}
.name{
color:#fff;
font-weight:bold;
width:30%;
display:block;
float:left;
}
.name-dark{
color:#787878;
font-weight:bold;
width:30%;
display:block;
float:left;
}
.value{
color:rgba(255, 255, 255, 0.7);
font-weight:light;
display:block;
float:left
width:70%;
}
.value-dark{
color:rgba(0, 0, 0, 0.4);
font-weight:light;
display:block;
float:left
width:70%;
}
</style>
</head>
<body>
<img src="images/ico/apple-touch-icon-57.png">
<div class="group"><span class="name">Name: </span><span class="value">'.$fname.' '.$lname.'</span></div>
<div class="group"><span class="name">Email: </span><span class="value">'.$email.'</span></div>
<div class="group"><span class="name">Phone: </span><span class="value">'.$phone.'</span></div>
<div class="group"><span class="name">Company: </span><span class="value">'.$company.'</span></div>
<div class="group-light"><span class="name-dark">List: </span><span class="value-dark">'.$list.'</span></div>
</body>
</html>';
$subject="Request Quote From ".$fname." ".$lname;
/*set up the email headers*/
$headers = 'From: ' . $fname." ".$lname ."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$random_hash = md5(date('r', time()));
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\r\n";
$message .= $attachment;
/*send the message and check if its been sent and respond accordingly*/
if (mail($to, $subject, $message, $headers)){
echo json_encode(array(
'status' => 'success',
'message' => 'Thank you, Your Quote has been received'
));
exit();
}
else{
echo json_encode(array(
'status' => 'error',
'message' => 'You message has not been sent please try again '.print_r(error_get_last())
));
exit();
}
}
?>