3v4l.org

run code in 300+ PHP versions simultaneously
<?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;
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
string(80) "Contact name: Firm name: Email: Job number: Document: Discount: Message: "

preferences:
99.33 ms | 407 KiB | 5 Q