PHP file for a form on exported sites

Hi guys, I was testing a way to send the form inputs to my email through a .php way.
I’ve never written in PHP so I don’t have a clue on where to begin.

My HTML code for the form is:

<div class="w-form">
    <form id="email-form" name="email-form" data-name="Email Form" method="post" action="sendform.php" class="form">
        <label for="name-2">Name Field</label>
        <input type="text" id="test-name" name="name" data-name="name" maxlength="256" class="w-input">
        <label for="email">Email Field</label>
        <input type="email" class="w-input" maxlength="256" name="email" data-name="Email" id="test-email" required="">
        <textarea id="test-text-1" name="text" placeholder="Example Text" maxlength="5000" data-name="text" class="w-input">
        </textarea>
      <div class="w-checkbox"><input type="checkbox" id="test-checkbox" name="checkbox" data-name="Checkbox" required="" class="w-checkbox-input">
          <label for="checkbox" class="w-form-label">Checkbox</label>
        </div><input type="text" class="w-input" maxlength="256" name="text-2" data-name="text-2" placeholder="Example Text" id="test-text-2" required="">
        <select id="test-choice" name="scelta" data-name="scelta" class="w-select">
            <option value="">Select one...</option>
            <option value="First">First Choice</option>
            <option value="Second">Second Choice</option>
            <option value="Third">Third Choice</option>
        </select><input type="submit" value="Submit" data-wait="Please wait..." class="w-button">
    </form>
    <div class="w-form-done">
      <div>Thank you! Your submission has been received!</div>
    </div>
    <div class="w-form-fail">
      <div>Oops! Something went wrong while submitting the form.</div>
    </div>
  </div>

And this is what I’ve been writing until now in PHP:

<?php 
$name = $_POST['name']; 
$email = $_POST['email']; 
$formcontent="From: $name \n Message: $message"; 
$recipient = "test@email.com"; 
$subject = "Contact Form"; 
$mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!";
?>

I’m still missing some code on the PHP file to get all infos submitted, can any hero please help me?

1 Like

Figuring something out, I succeed to correctly submit some more fields, but there is still missing something:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$text = $_POST ['text'];
$checkbox = $_POST ['checkbox'];
$formcontent = "
Name: $name \n
Email: $email \n
Text: $text \n
Checkbox: $checkbox \n";
$recipient = "test@email.it";
$subject = "Contact form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader)
    or die("Error");
echo "Submitted";
?>

I still need the second label and the dropdown choice.

Your checkbox has no value attribute so it’s passing nothing?

Your PHP script does not use the scelta value at all.

I just came up with the code, I’ll leave you here just in case:

<?php

if(isset($_POST['name'])){  
    
    $a = $_POST['name'];
    $b = $_POST['email'];
    $c = $_POST['phone'];
    
    $headers =  'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: CustomFromAdress' . "\r\n";
    
    // Email Variables
    $toUser  = "your@email.com"; // recipient
    $subject = "Your Subject"; // subject
    $body    = "<html><body><p>
          Name: ".$a."<br>
          Email adress: ".$b."<br>
          Phone number: ".$c."<br>
          </p></body></html>"; // content
    
    if (mail($toUser,$subject,$body,$headers)) {
        echo "Form submitted.";
    } else {
        echo "An error occurred, try again.";
    }

}else{
  echo '<script>window.location.href = "redirect page";</script>';
}



?>

Glad you got it figured out.

Hey Paul,
I have the same form sending problem but I don’t know anything about code.
Could you tell me or place this code?
Thank you

1 Like