php not functioning properly

I am building a website and have added a form to my site under by contact us page. I have been having trouble getting the form to function properly. Below is the HTML code from the site page and the PHP code from my php file. Any advise would be greatly appreciated on how to get this to function properly. Thank you in advance!

HTML:[code]

get in touch

Message:
clear
<a href="Feedback.php" class="link-1" onClick= [/code]

PHP:[php]
<php
$mail_to_send_to = "[email protected]";
$your_feedbackmail = "[email protected]";
$subject = “Contact Us”;
{
$Name = $_REQUEST[‘Name’] ;
$E-Mail = $_REQUEST[‘E-Mail’] ;
$Phone = $_REQUEST[‘Phone’] ;
$Message = $_REQUEST[‘Message’] ;
$headers = “From: [email protected]” . “\r\n” . “Reply-To: [email protected]” . “\r\n” . “Name: $name” . “\r\n” ;
$a = mail( [email protected], “PW Contact Us Message”, $message, $headers );
}

Contact Form PHP
Thank you
Your message has been sent

Click here return to homepage

[/php]

Alot going on there…at first look heres what i see.

on your form…
1- your form doesnt have a POST or GET method
2-There is no SUBMIT input
and on your feedback.php…
1-your opening and closing php tags are missing ? should be [php]<?php //code here ?>[/php]
2-your E-mail variable shouldnt have a dash it should look like [php]$E_mail[/php]
3 - your $_REQUEST is calling for values that dont exist. (in your form you assigned your values to include “:”)

In addition to what Journeyman1900 said,

Your form action isn’t being properly assigned. You are using two equal signs “==” and it should be one “=”

NONE of your inputs are named. They will not work without a name.

In your feedback.php form:

You should be checking if the form was submitted prior to doing any processing.

You are setting $Name and $Message, but using them later as $name and $message. PHP is case sensitive and these are four completely different variables.

Your mail function call needs to have quotes around the string literals. Or use the variables that you are setting at the beginning of the script instead.

You are using depreciated elements and should switch to CSS instead.

I am assuming that the form that you posted is part of a bigger page. If not, you need to include the appropriate elements for an html page, and your last line is incomplete.

Lastly, I would move you php to the page’s body. This way, if it fails, the doctype and head elements are still being created.

Here is an example that makes the changes above, as well as those recommended by Journeyman1900:
[php]

get in touch

Message:
[/php]

Here is an example of the recommended changes applied to your Feedback.php file:[php]

Contact Form PHP <?php if(isset($_POST['submit'])) { $Name = $_POST['Name']; $E_Mail = $_POST['E-Mail']; $Phone = $_POST['Phone']; $Message = $_POST['Message']; $mail_to_send_to = "[email protected]"; $your_feedbackmail = "[email protected]"; $subject = "Contact Us"; $headers = "From: [email protected]" . "\r\n" . "Reply-To: $your_feedbackmail" . "\r\n" . "Name: $Name" . "\r\n" ; $a = mail( $mail_to_send_to, "PW Contact Us Message", $Message, $headers ); } else die('You did not enter all required information. Please go back and complete the form.'); ?>
Thank you <?php echo $Name; ?>
Your message has been sent

Click here return to homepage

[/php]

Try making these changes and then let us know where things are at. There is a lot here, so please feel free to ask any questions you may have.

Thank you Journeyman1900 and malasho for your feedback, very helpful.

When I put in the HTML code into the form it creates a new submit button. I have custom submit button that i would like to utilize. Below is the HTML for the Form.

[code]

get in touch

Message:
                                    <div class="container"> 
                                       <div class="fright"> 
                                           <a href="index-6.html" class="link-1" onClick="submit">clear</a>
                                           <input name="submit" type="submit" value="submit"><div class="indent-2"><a href="Feedback.php" class="link-1" onClick="submit">                                                submit</a></div></form>[/code]

The PHP part worked. The HTML code you helped me with created a new submit button, when I click the new submit button it works but in the email i get it only provides the information that is in the message field of the form and not the “name”, “phone”, or “email”. Below is my updated PHP code.

PHP:[php]

Contact Form PHP <?php if(isset($_POST['submit'])) { $Name = $_POST['Name']; $E_Mail = $_POST['E-Mail']; $Phone = $_POST['Phone']; $Message = $_POST['Message']; $mail_to_send_to = "[email protected]"; $your_feedbackmail = "[email protected]"; $subject = "Contact Us"; $headers = "From: [email protected]" . "\r\n" . "Reply-To: $your_feedbackmail" . "\r\n" . "Name: $Name" . "\r\n" ; $a = mail( $mail_to_send_to, "PW Contact Us Message", $Message, $headers ); } else die('You did not enter all required information. Please go back and complete the form.'); ?> Your Page Title Optional page text here. [/php]

in your html you have semicolons beside your values. look at your message input. you’ll notice it is the only one working because it is the only one that is missing the semicolon.

and by semicolon i mean colon…sorry “:”

The form code that you posted did not include a valid submit element so I added one. It appears that it got truncated, as your most recent post includes the rest of the line.

You cannot submit your form the way you are trying to. You need to do something like this instead:[php]submit[/php]

I have no idea what your intent is regarding the other link that is marked clear. I would guess that you intend to have it reset the form, if that is you intent, try this:[php]clear[/php]

You are using an html fieldset but you have no closing fieldset tag. I don’t know where you want it, so I guessed, but you may need to change it. Also, if you use the fieldset tag, you must also include a legend. I have added this element for you.

You are missing two closing div tags in the end section of your form.

As I mentioned previously, this is not a complete document. You need to make sure that the page it appears on has an appropriate doctype, head, title, and that this code is inside the body. You also need to make sure you include the appropriate end tags for each of these elements.

Here is the reworked form as a complete document (using the same doctype you used in your Feedback.php file):[php]

Feedback Form

get in touch

Please complete the following information
Message:
clear
[/php]

If this is going into an existing page, only copy and paste the appropriate form section. See note regarding this below.

You Feedback.php file now has two doctypes, and heads. This is invalid markup and needs to be fixed. In addition, since we eliminated the submit button, we will need to change the isset check.

The reason that you are not getting the name, phone number, or email is that you aren’t including them in the message that you are sending. I have changed your message to include them.

Try this:[php]

Contact Form PHP <?php if(isset($_POST['Name'],$_POST['E-Mail'],$_POST['Phone'],$_POST['Message'])) { $Name = $_POST['Name']; $E_Mail = $_POST['E-Mail']; $Phone = $_POST['Phone']; $Message = "$Name\r\n$E_Mail\r\n$Phone\r\n\r\n\r\n"; $Message .= $_POST['Message']; $mail_to_send_to = "[email protected]"; $your_feedbackmail = "[email protected]"; $subject = "Contact Us"; $headers = "From: [email protected]" . "\r\n" . "Reply-To: $your_feedbackmail" . "\r\n" . "Name: $Name" . "\r\n" ; $a = mail( $mail_to_send_to, "PW Contact Us Message", $Message, $headers ); } else die('You did not enter all required information. Please go back and complete the form.'); ?>

Optional page text here.

[/php]

THANK YOU malasho and Journeyman1900. I have been stuck for a month on this. Everything worked perfectly!!

Sponsor our Newsletter | Privacy Policy | Terms of Service