<?php
// get all form values
$input['Contact name'] = $_POST['contact_name'] ?? '';
$input['Firm name'] = $_POST['firm_name'] ?? '';
$input['Email'] = $_POST['email'] ?? '';
$input['Job number'] = $_POST['job_number'] ?? '';
$input['Document'] = $_POST['document'] ?? '';
$input['Discount'] = $_POST['discount'] ?? '';
$input['Message'] = $_POST['message'] ?? '';
// generate the email content (i.e. each line is like "Contact name: Mark")
$formContent = '';
foreach($input as $key => $value) {
$formContent .= $key . ": " . $value . "\n";
}
$to = "my@email.com"; // TODO: replace this with your email address
$subject = "Contact Form";
/*
Note that this is likely part of the issue. Most email clients (gmail, outlook) will mark emails as spam
if you try to send an email from an email address that your server isn't configured to send from.
See https://stackoverflow.com/questions/17533863/how-to-configure-php-to-send-e-mail for more info.
*/
$mailheader = "From: " . $input['Email'];
// for this example, output $formContent and end the script because mail() isn't allowed here
var_dump($formContent);
die();
mail($to, $subject, $formContent, $mailheader) or die('Error sending email');
// redirect to the thank you page
// TODO: update this URL to be yours
header('Location: http://www.example.com/thankyou.html');
exit;