0

I have been trying to get a website form submission to send an email. I have made sure that the mail command works so I'm out of ideas on what I'm doing wrong. Please help. Thanks in advance!

I have been sent to other PHP submission code on stackoverflow and it still does not work.

HTML Code:

 <form action="/includes/support_form.php" form id="support_form" method="POST">
                        <div class="form-group">
                            <label>
                                Name
                            </label>
                            <input id="name" class="form-control" type="text" name="name" required />
                        </div>
                        <div class="form-group">
                            <label>
                                Email
                            </label>
                            <input id="email" class="form-control" type="email" name="email" required />
                        </div>
                        <div class="form-group">
                            <label>
                                Company Name
                            </label>
                            <input id="company" class="form-control" type="text" name="company" required />
                        </div>
                        <div class="form-group">
                            <label>
                                Phone Number
                            </label>
                            <input id="phone" class="form-control" type="text" name="phone" required />
                        </div>
                        <div class="form-group">
                            <label>
                                About Your Business
                            </label><textarea id="message" class="form-control" rows="4" cols="50" name="message" required></textarea>
                        </div>
                        <div class="form-group">
                            <label>
                                Please Contact me by
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="radioSetOne" value="option1" id="input_342" />Email
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="radioSetOne" value="option2" id="input_2152" />Phone
                            </label>
                        </div>
                        <button class="bloc-button btn btn-lg btn-block btn-sea-green" type="submit">
                            Submit
                        </button>
                    </form>

This is the support_form.php file I have to collect the data and send the email.

<?php   
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['company']) || empty($_POST['phone']) || empty($_POST['message']) || empty($_POST['input_342']) || empty($_POST['input_2152']))
{
    return false;
}

$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$input_342 = $_POST['input_342'];
$input_2152 = $_POST['input_2152'];

$to = 'xxxx@gmail.com'; // Email submissions are sent to this email

// Create email 
$email_subject = "Message from My Site.";
$email_body = "You have received a new message. \n\n".
              "Name: $name \nEmail: $email \nEmail: $email \nEmail: $email \nMessage: $message \nInput_342: $input_342 \nInput_2152: $input_2152 \n";
$headers = "From: xxxx@gmail.com\n";
$headers .= "Reply-To: $email"; 

mail($to,$email_subject,$email_body,$headers); // Post message
return true; ?>
Troy Wilson
  • 79
  • 2
  • 10

0 Answers0