|
1 | 1 | <?php |
2 | 2 |
|
3 | | -// enable errors => debug mode. |
4 | | -ini_set('display_errors', 1); |
5 | | -error_reporting(E_ALL); |
6 | | - |
7 | 3 | // init autoload. |
8 | 4 | require __DIR__ . '/../vendor/autoload.php'; |
9 | 5 |
|
|
16 | 12 | 'fields' => [ |
17 | 13 | 'name' => ['required'], |
18 | 14 | 'email' => ['required', 'email'], |
19 | | - 'subject' => ['required'], |
20 | 15 | 'message' => [ |
21 | 16 | 'required', |
22 | 17 | ['lengthMin', 5] |
23 | 18 | ], |
24 | | - 'cv_file' => [ |
| 19 | + 'cv' => [ // this is file field. |
25 | 20 | [ |
26 | 21 | 'required', |
27 | 22 | 'message' => 'Please upload {field}', |
28 | 23 | ], |
29 | 24 | [ |
30 | 25 | 'file', |
31 | | - ['jpeg', 'jpg', 'png'], // types. |
32 | | - 2000000, // size limit 2 MB. |
| 26 | + ['jpeg', 'jpg', 'png', 'pdf'], // types. |
| 27 | + 2000000, // size limit 2 MB. |
33 | 28 | 'message' => '{field} should be up to 2MB and allows only file types jpeg, png.', |
34 | 29 | ], |
35 | 30 | ], |
| 31 | + 'links.*' => ['url'], |
36 | 32 | ], // according to Valitron doc for mapFieldsRules. |
37 | 33 | 'labels' => [ |
38 | 34 | 'name' => 'Name', |
39 | | - 'email' => 'Email address' |
| 35 | + 'email' => 'Email address', |
| 36 | + 'message' => 'About you', |
| 37 | + 'cv' => 'CV', |
| 38 | + 'links.*' => 'Links', |
40 | 39 | ] // according to Valitron doc. |
41 | 40 | ]; |
42 | 41 |
|
43 | 42 | // Mandrill config. |
44 | 43 | $mailerConfig = [ |
45 | | - 'mailer' => MailHandler::USE_MANDRILL, // (or USE_POSTMARKAPP, USE_MANDRILL) |
46 | | - 'apiKey' => '_5mPSvb39BQqnA7G_dOaAA', |
| 44 | + 'mailer' => MailHandler::USE_PHPMAILER, |
| 45 | + 'host' => 'SMTP HOST', // set your smtp host. |
| 46 | + 'user' => 'YOUR EMAIL', // set email. |
| 47 | + 'password' => 'YOUR PASSWORD', // set password. |
| 48 | + 'protocol' => 'tls', // 'tls', 'ssl' or FALSE for not secure protocol/ |
| 49 | + 'port' => 587, // your port. |
| 50 | + |
47 | 51 | 'attachmentsSizeLimit' => 8000000, // around 8MB. |
48 | 52 | ]; |
49 | 53 |
|
| 54 | +// File manager config. |
50 | 55 | $fileManager = new FileManager([ |
51 | 56 | 'uploadPath' => __DIR__ . '/attachments', |
52 | 57 | 'uploadUrl' => 'http://MY-DOMAIN.COM/attachments', |
53 | 58 | ]); |
54 | 59 |
|
55 | 60 | $message = [ |
56 | | - 'from' => ['hello@justcoded.co.uk' => 'FROM NAME'], |
57 | | - 'to' => ['kostant21@yahoo.com' => 'TO NAME'], |
58 | | -// 'cc' => ['email' => 'name'], |
59 | | -// 'bcc' => ['email' => 'name'], |
| 61 | + 'from' => ['FROM.EMAIL@DOMAIN.COM' => 'FROM NAME'], // set correct FROM. |
| 62 | + 'to' => ['TO.EMAIL@DOMAIN.COM' => 'TO NAME'], // set correct TO. |
| 63 | + 'cc' => ['CC@DOMAIN.COM' => 'CC NAME'], |
| 64 | + 'bcc' => ['BCC@DOMAIN.COM'], |
| 65 | + |
60 | 66 | 'subject' => 'Contact request from {name}', |
61 | 67 | 'bodyTemplate' => __DIR__ . '/template-html.php', |
62 | 68 | 'altBodyTemplate' => __DIR__ . '/template-plain.php', |
63 | 69 | 'attachments' => $fileManager->upload([ |
64 | | - 'cv_file', 'image_file' |
| 70 | + 'cv', |
65 | 71 | ]) |
66 | 72 | ]; |
67 | 73 |
|
|
73 | 79 | $formHandler->process(); |
74 | 80 | } |
75 | 81 |
|
76 | | -echo json_encode($formHandler->response()); |
| 82 | +// write errors and return back. |
| 83 | +setcookie('advanced_response', $formHandler->response()); |
| 84 | +header('Location: index.php'); |
| 85 | +exit; |
0 commit comments