From 827ba39277c7d89b565eacf9d89f13a2ff7b8c76 Mon Sep 17 00:00:00 2001 From: s22-tech <59073912+s22-tech@users.noreply.github.com> Date: Mon, 11 Apr 2022 08:29:11 -0700 Subject: [PATCH 1/3] PHP 8 changes --- contact-form.php | 80 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/contact-form.php b/contact-form.php index bab6b70..08321a6 100644 --- a/contact-form.php +++ b/contact-form.php @@ -2,49 +2,71 @@ // BEGIN CONFIGURATION //////////////////////////////////////////////// define('EMAIL_TO', 'your-email@address.com'); -define('EMAIL_SUBJECT', 'Test Subject'); -define('CAPTCHA_ENABLED', '1'); // 0 - Disabled, 1 - Enabled +define('EMAIL_SUBJECT', 'Test Form'); +define('CAPTCHA_ENABLED', '1'); // 0 - Disabled, 1 - Enabled // END CONFIGURATION //////////////////////////////////////////////// define('CAPTCHA1', rand(1,9)); define('CAPTCHA2', rand(1,9)); +if (empty($name)) $name = ''; +if (empty($email)) $email = ''; +if (empty($message)) $message = ''; +if (empty($msg)) $msg = ''; + if ($_POST) { - $name = $_POST['name']; - $email = $_POST['email']; - $message = $_POST['message']; - $captcha = $_POST['captcha']; + $name = $_POST['name']; + $email = $_POST['email']; + $message = $_POST['message']; + $captcha = $_POST['captcha']; $captcha1 = $_POST['captcha1']; $captcha2 = $_POST['captcha2']; -// If captcha disabled, set variable values to avoid error + // If captcha disabled, set variable values to avoid error. if (CAPTCHA_ENABLED == '0') { $captcha1 = '1'; $captcha2 = '1'; $captcha = '2'; } -// Error handling - if (empty($name) || empty($email) || empty($message)) { $msg = 'One or more fields is blank!'; } - else if (!$email == '' && (!strstr($email,'@') || !strstr($email,'.'))) { $msg = 'Your email address is not formatted correctly!'; } - else if (($captcha1 + $captcha2) != $captcha) { $msg = 'Anti-spam incorrect! Please try again.'; } + // Error handling. + if (empty($name) || empty($email) || empty($message)) { + $msg = 'One or more fields were left empty!'; + } + else if (!$email == '' && (!strstr($email, '@') || !strstr($email, '.'))) { + $msg = 'Your email address is not formatted correctly!'; + } + else if (($captcha1 + $captcha2) != $captcha) { + $msg = 'Your anti-spam answer is incorrect! Please try again.'; + } -// Build email headers + // Build email headers. else { - $headers = "From: ".$name." <".$email.">\r\n"; - $headers .= "Reply-To: ".$name." <".$email.">\r\n"; - $headers .= "MIME-Version: 1.0\r\n"; - $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; + $headers['MIME-Version'] = '1.0'; + $headers['Content-type'] = 'text/html;charset=UTF-8'; + $headers['Return-Path'] = 'your-email@address.com'; + $headers['From'] = $name.' <'.$email.'>'; + $headers['Reply-To'] = $name.' <'.$email.'>'; -// Build email body + // Build email body. $body = ' -
+ + +'.$email_subject.' | |
Name: | '.$name.' ('.$email.') |
Message: | '.$message.' |
'.EMAIL_SUBJECT.' | +|
Name: | '.$name.' ('.$email.') | +
Message: | '.$message.' | +