-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.php
309 lines (271 loc) · 10.5 KB
/
mailer.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
$errmsg = "";
$results = ""; // to send data back to ajax call
function clean($data) {
$data = trim(stripslashes(strip_tags($data)));
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$results = "request method = post";
// collect, sanitize, validate input
if (empty($_POST['name'])) {
$errmsg .= "Missing required information: NAME<br />";
} else {
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$errmsg .= "Only letters and white space allowed in NAME field<br />";
} else {
$name = clean(filter_var($_POST['name'], FILTER_SANITIZE_STRING));
}
}
if (empty($_POST['email'])) {
$errmsg .= "Missing required information: EMAIL<br />";
} else {
if (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) {
$errmsg .= "Invalid email format<br />";
} else {
$email = clean(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL));
}
}
if(isset($_POST['income'])) {
$income = ($_POST['income']);
// switch case to convert value to useable info
switch ($income) {
case 'a':
$incomeStatement = "Estimated monthly income is less than $2,500.";
break;
case 'b':
$incomeStatement = "Estimated monthly income is between $2,500 and $4,000.";
break;
case 'c':
$incomeStatement = "Estimated monthly income is between $4,000 and $6,000.";
break;
case 'd':
$incomeStatement = "Estimated monthly income is over $6,000.";
break;
case 'e':
$incomeStatement = "Unsure of estimated monthly income at this time.";
break;
default:
$incomeStatement = "Estimated monthly income not selected.";
}
} else { $incomeStatement = "Estimated monthly income not selected."; }
if(isset($_POST['debt'])) {
$debt = ($_POST['debt']);
// switch case to convert value to useable info
switch ($debt) {
case 'a':
$debtStatement = "Estimated monthly debt is less than $500.";
break;
case 'b':
$debtStatement = "Estimated monthly debt is between $500 and $1,000.";
break;
case 'c':
$debtStatement = "Estimated monthly debt is between $1,000 and $1,500.";
break;
case 'd':
$debtStatement = "Estimated monthly debt is over $1,500.";
break;
case 'e':
$debtStatement = "Unsure of estimated monthly debt at this time.";
break;
default:
$debtStatement = "Estimated monthly debt not selected.";
}
} else { $debtStatement = "Estimated monthly debt not selected."; }
if(isset($_POST['score'])) {
$score = ($_POST['score']);
// switch case to convert value to useable info
switch ($score) {
case 'a':
$scoreStatement = "Estimated FICO score is less than 600.";
break;
case 'b':
$scoreStatement = "Estimated FICO score is between 600 and 649.";
break;
case 'c':
$scoreStatement = "Estimated FICO score is between 650 and 700.";
break;
case 'd':
$scoreStatement = "Estimated FICO score is over 700.";
break;
case 'e':
$scoreStatement = "Unsure of FICO score at this time.";
break;
default:
$scoreStatement = "Estimated FICO score not selected.";
}
} else { $scoreStatement = "Estimated FICO score not selected."; }
if(isset($_POST['late'])) {
$late = ($_POST['late']);
// switch case to convert value to useable info
switch ($late) {
case 'y':
$lateStatement = "Yes, there has been a late payment in the last 12 months.";
break;
case 'n':
$lateStatement = "No, there has not been a late payment in the last 12 months.";
break;
default:
$lateStatement = "Late payments question not answered.";
}
} else { $lateStatement = "Late payments question not answered."; }
if(isset($_POST['bankrupt'])) {
$bankrupt = ($_POST['bankrupt']);
// switch case to convert value to useable info
switch ($bankrupt) {
case 'y':
$bankruptStatement = "Yes, there has been a bankruptcy in the last 7 years.";
break;
case 'n':
$bankruptStatement = "No, there has not been a bankruptcy in the last 7 years.";
break;
default:
$bankruptStatement = "Bankruptcy question not answered.";
}
} else { $bankruptStatement = "Bankruptcy question not answered."; }
if(isset($_POST['selling'])) {
$selling = ($_POST['selling']);
// switch case to convert value to useable info
switch ($selling) {
case 'y':
$sellingStatement = "Yes, there is a home to sell as well.";
break;
case 'n':
$sellingStatement = "No, there is no home to sell at this time.";
break;
default:
$sellingStatement = "Selling a home question not answered.";
}
} else { $sellingStatement = "Selling a home question not answered."; }
if(isset($_POST['buynow'])) {
$buynow = ($_POST['buynow']);
// switch case to convert value to useable info
switch ($buynow) {
case 'y':
$buynowStatement = "Yes, ready to purchase a new home in the next 3 months.";
break;
case 'n':
$buynowStatement = "No, not ready to purchase a new home in the next 3 months.";
break;
case 'u':
$buynowStatement = "Unsure if ready to purchase a new home right now.";
break;
default:
$buynowStatement = "Ready to purchase question not answered.";
}
} else { $buynowStatement = "Ready to purchase question not answered."; }
if(isset($_POST['down'])) {
$down = ($_POST['down']);
// switch case to convert value to useable info
switch ($down) {
case 'a':
$downpayStatement = "Current ammount available for a down payemnt is less than $2,500.";
break;
case 'b':
$downpayStatement = "Current ammount available for a down payemnt is between $2,500 and $4,000.";
break;
case 'c':
$downpayStatement = "Current ammount available for a down payemnt is between $4,000 and $6,000.";
break;
case 'd':
$downpayStatement = "Current ammount available for a down payemnt is over $6,000.";
break;
case 'e':
$downpayStatement = "Unsure of available amount for a down payment at this time.";
break;
default:
$downpayStatement = "Down payment amount not selected.";
}
} else { $downpayStatement = "Down payment amount not selected."; }
if(isset($_POST['location'])) {
$locationStatement = "Looking to buy within the following location(s): ";
foreach (($_POST['location']) as $location) {
$locationStatement .= $location ." ";
}
} else {
$locationStatement = "No purchase location was selected.";
}
if(isset($_POST['via'])) {
$contactMethod = ($_POST['via']);
$contactStatement = "Best way to reach out: " . $contactMethod . " ";
if ($contactMethod == 'phone') {
if(empty($_POST['telephone'])) {
$errmsg .= "Phone number missing<br />";
} else {
$phoneNum = clean(filter_var($_POST['phone'], FILTER_SANITIZE_NUMBER_INT));
$contactStatement .= "at " . $phoneNum . " ";
}
} else {
$contactStatement .= ": " . $email . " ";
}
} else { $contactStatement = "No preferred contact method selected."; }
if(isset($_POST['timeofday'])) {
$contactStatement .= "\r\nBest time to reach out is ";
foreach (($_POST['timeofday']) as $daytime) {
$contactStatement .= $daytime . " ";
}
} else {
$contactStatement .= "\r\nNo time of day was seleceted as best to be contacted.";
}
if (empty($_POST['comments'])) {
$comments = "no comment supplied";
} else {
$comments = clean(filter_var($_POST['comments'], FILTER_SANITIZE_STRING));
}
if(empty($errmsg)) {
// message one = email to site owners
$results = "No error messages - proceed to build. \r\n";
$to1 = /*insert receiving email address here*/;
$subject1 = "Form submission from WAHomeGrants.com";
$message1 = "Someone has completed the form on WAHomeGrants.com - Please see the details below: \r\n";
$message1 .= "Name/Email: " . $name ." [" . $email . "]\r\n";
$message1 .= "Message/Comments: " . $comments . "\r\n\r\n";
$message1 .= $incomeStatement . "\r\n";
$message1 .= $debtStatement . "\r\n";
$message1 .= $scoreStatement . "\r\n";
$message1 .= $lateStatement . "\r\n";
$message1 .= $bankruptStatement . "\r\n";
$message1 .= $sellingStatement . "\r\n";
$message1 .= $buynowStatement . "\r\n";
$message1 .= $downpayStatement . "\r\n";
$message1 .= $locationStatement . "\r\n";
$message1 .= $contactStatement . "\r\n";
$headers1 = "From: $name <$email>\r\n";
$headers1 .= "Reply-To: $email\r\n";
$mail1status = mail($to1, $subject1, $message1, $headers1);
if ($mail1status) {
$results = "Your message has been sent! Watch your inbox for more information.";
// message two = confirmation email to site visitor
$to2 = $email;
$subject2 = "Thank you for visiting WAHomeGrants.com";
$message2 = $name. ", \r\n\r\n";
$message2 .= "Thank you for visiting WAHomeGrants.com and completing our form. Below are the details you submitted: \r\n";
$message2 .= "Name/Email: " . $name ." [" . $email . "]\r\n";
$message2 .= "Message/Comments: " . $comments . "\r\n\r\n";
$message2 .= $incomeStatement . "\r\n";
$message2 .= $debtStatement . "\r\n";
$message2 .= $scoreStatement . "\r\n";
$message2 .= $lateStatement . "\r\n";
$message2 .= $bankruptStatement . "\r\n";
$message2 .= $sellingStatement . "\r\n";
$message2 .= $buynowStatement . "\r\n";
$message2 .= $downpayStatement . "\r\n";
$message2 .= $locationStatement . "\r\n";
$message2 .= $contactStatement . "\r\n\r\n";
// add more content here as defined by Skip and/or Traci
$message2 .= "Please note, none of this information is stored or otherwise saved, and it will be used solely for the purpose of providing home-buying guidance and possibly free down payment assistance. You have not been added to any mailing lists, however you may still receive messages with more information regarding this subject. If you would rather not receive these, simply reply to this email with the subject line 'REMOVE'.\r\n\r\n";
$message2 .= "A certified loan professional will be in touch with you directly within 2 business days.";
$mail2status = mail($to2, $subject2, $message2, $headers2);
if($mail2status == 1) { $results .= " Second message sent."; }
} else { // mail 1 not sent
$results = $errmsg;
}
// if error messages present and message not created
} else {
$results = $errmsg;
}
} else {
$results = "Could not execute - request method != POST";
}
echo $results;
?>