1

I am working on my new website, I am using a template but editing the contents with notepad++. I am currently editing the contact me page in which i am struggling to find a solution to sending the form data to a PHP script which will then send it as an email to me. I have created a PHP script that i think is ok to do the job but it is not working. After I submit some information into the text boxes then click submit it just redirects me to the PHP file in which looks to contain nothing. I have uploaded both the contact page and PHP file to my web server in which the same thing happens only now I will receive an email with none of the information I have entered only the "Hi my name is " stated within the PHP file. I am wondering if anybody knows what the issue is, I have spent majority of the day trying to work this out without luck. I will post both my HTML and PHP code below.

(p.s. I am aware that my "Reason for contact" part of the form will not send as I am still trying to work that one out.

Thanks in advance.

HTML

<form name="cForm" id="cForm" action="http://www.richardmotion.com/form-to-email.php" method="post">
    <fieldset>
        <div class="form-field">
            <input name="cName" type="text" id="cName" class="full-width" placeholder="Your Name" value="">
        </div>
        <div class="form-field">
            <input name="cEmail" type="text" id="cEmail" class="full-width" placeholder="Your Email" value="">
        </div>
        <div>
            <label for="sampleRecipientInput">Reason For Contacting</label>
            <div class="ss-custom-select">
                <select class="full-width" id="sampleRecipientInput">
                    <option value="Option 3">General Enquiry</option>
                    <option value="Option 1">Question About A Guide</option>
                    <option value="Option 2">Question About A Review</option>
                </select>
            </div>
        </div>
        <div class="message form-field">
            <textarea name="cMessage" id="cMessage" class="full-width" placeholder="Your Message"></textarea>
        </div>
        <button type="submit" name="submit" value="Submit" class="submit button-primary full-width-on-mobile">Submit</button>
    </fieldset>
</form>

PHP

<?php
    $cName = $_POST['name'];
    $cEmail = $_POST['email'];
    $cWebsite = $_POST['website'];
    $cMessage = $_POST['message'];
?>

<?php
    $email_from = '[email protected]';
    $email_subject = "Website Enquiry";
    $email_body = "Hi my name is $name,\n
                   \n
                   $message"
?>

<?php
  $to = "[email protected]";
  $headers = "From: $email_from \r\n";
  $headers .= "Reply-To: $cEmail \r\n";
  mail($to,$email_subject,$email_body,$headers);
 ?>
0

2 Answers 2

3

Issue with input name filed

$cName = $_POST['cName'];
$cEmail = $_POST['cEmail'];
$cMessage = $_POST['cMessage'];

And select tag has no name atrribute

Sign up to request clarification or add additional context in comments.

2 Comments

Great it did fix my problem thanks i have it working now, the only issue is it is still redirecting me to a my PHP file. Do you know why it is doing this and how to fix it?
You need to add header('Location:html_file_name.php'); in your php file at end of the file
0
  1. Your server needs to have a handler for mail() configured, otherwise it will not send. See this for details: Installing/Configuring Mail. You can also use SendGrid or Google Apps or various other services for sending emails.

  2. Your select needs a name for it to send the variable
    ..select name="reason" class="full-width" id="sampleRecipientInput">

1 Comment

Great it did fix my problem thanks i have it working now, the only issue is it is still redirecting me to a my PHP file. Do you know why it is doing this and how to fix it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.