} elseif ('email' == $fieldKey) { if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $response['errors'][$fieldKey] = 'Please check your email address.'; } } } if (empty($response['errors'])) { // headers creation $headers = array(); if (!empty($emailData['email'])) { $headers['reply'] = 'Reply-To: ' . strip_tags($emailData['email']); } $headers['mime'] = 'MIME-Version: 1.0'; $headers['contentType'] = 'Content-Type: text/html; charset=utf-8'; // message text generation $notificationText = fetchNotificationBody($emailData); if (mail(NOTIFICATION_EMAIL_ADDRESS, NOTIFICATION_SUBJECT, $notificationText, join("\r\n", $headers))) { $response['success'] = true; $response['message'] = 'Your message was sent successfully. Thanks.'; } else { throw new Exception('Some technical issue with mail sending. Please contact support.'); } } } catch (Exception $e) { $response['errors'][] = $e->getMessage(); } if (!$response['success']) { http_response_code(400); } elseif (empty($response['errors'])) { unset($response['errors']); }
if (empty($value)) { $response['errors'][$fieldKey] = 'Please complete all required fields.'; } elseif ('email' == $fieldKey) { if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $response['errors'][$fieldKey] = 'Please check your email address.'; } } } if (empty($response['errors'])) { require __DIR__ . '/vendor/autoload.php'; //lib/swift_required.php // Create the Transport $transport = Swift_SmtpTransport::newInstance(SMTP_HOST, SMTP_PORT, SMTP_SCHEME)->setUsername(SMTP_USER)->setPassword(SMTP_PASSWORD); $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance(NOTIFICATION_SUBJECT)->setTo(array(NOTIFICATION_EMAIL_ADDRESS))->setBody(fetchNotificationBody($emailData)); $type = $message->getHeaders()->get('Content-Type'); $type->setValue('text/html'); $type->setParameter('charset', 'utf-8'); $message->getHeaders()->get('MIME-Version')->setValue('1.0'); if (!empty($emailData['email'])) { $message->getHeaders()->addTextHeader('Reply-To', strip_tags($emailData['email'])); } if ($mailer->send($message)) { $response['success'] = true; $response['message'] = 'Your message was sent successfully. Thanks.'; } else { throw new Exception('Some technical issue with mail sending. Please contact support.'); } } } catch (Exception $e) {