$max_message_length) { $error = true; } if (!$error) { // Construct the mail with headers. $name = _contact_clean_str($_POST['name'], ENT_QUOTES, true, true, true); $prefix = _contact_clean_str($prefix, ENT_NOQUOTES, true, true, true); $subject = _contact_clean_str($_POST['subject'], ENT_NOQUOTES, true, true, true); $subject = "[$prefix] $subject"; $message = _contact_clean_str($_POST['message'], ENT_NOQUOTES); $lines = explode("\n", $message); array_walk($lines, '_contact_ff_wrap'); $message = implode("\n", $lines); $headers = [ 'From' => "$name <$email>", 'Sender' => $sender, 'Return-Path' => $sender, 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', 'Content-Transfer-Encoding' => '8Bit', 'X-Mailer' => 'Hugo - Zen', ]; $mime_headers = []; foreach ($headers as $key => $value) { $mime_headers[] = "$key: $value"; } $mail_headers = join("\n", $mime_headers); // Send the mail, suppressing errors and setting Return-Path with the "-f" option. $success = @mail($to, $subject, $message, $mail_headers, '-f' . $sender); } $status = $success ? 'submitted' : 'error'; $contact_form_url = strtok($_SERVER['HTTP_REFERER'], '?'); // Redirect back to contact form with status. header('Location: ' . $contact_form_url . '?' . $status, TRUE, 302); exit; function _contact_ff_wrap(&$line) { $line = wordwrap($line, 72, " \n"); } function _contact_clean_str($str, $quotes, $strip_tags = false, $strip_newlines = false, $encode = false) { if ($strip_tags) { $str = strip_tags($str); } if ($strip_newlines) { $str = str_replace(["\r", "\n"], '', $str); } $str = htmlspecialchars(trim($str), $quotes, 'UTF-8'); if ($encode && preg_match('/[^\x20-\x7E]/', $str)) { $str = '=?UTF-8?B?' . base64_encode($str) . '?='; } return $str; }