Jump to content

PHP Form - Very basic code, need assistance!


lauriedunsire

Recommended Posts

Hi everyone,

 

I'm requiring some help with a simple PHP form used on a website for one of my clients.  I am a novice when it comes to PHP, to say the least, and I just really used it for contact forms on websites that I produce. I use the same standard template which has always worked fine, however today one site has just stopped recieving anything - not sure how long it has not been working for but they certainly haven't receieved anything recently - so I'm worried it may be the same on all my sites.

 

Basically the contact page itself has the following for on it:

 

<FORM name=form4 action=sendinfo3.php method=post>
                Full Name:
                  <br>
                  <INPUT name=Name:>
                  <br>
                  <br>
                  Full Company Name:
                  <br>
                  <INPUT name=Company:>
                  <br>
                  <br>
                  Company Telephone Number:
                  <br>  
                  <INPUT name=Telephone:>
                  <br>
                  <br>
                  Company Email Address:
                  <br>
                  <INPUT name=email:>
                  <br>
                  <br>
                  Reference Number:
                  <br>
                  <INPUT name=Reference:>
                  <br>
                  <P>
                  <INPUT type=reset value=Reset name=Reset>
                </P>
                <P>
                  <INPUT type=submit value=Submit name=Submit>
                  <span class="style6">*Please ensure you fill out <strong>every</strong> field in the form. </span> </P>
                <P></P>
              </FORM>

 

And the 'sendinfo3.php' file contains the following:

 

<?

$message1 =$_REQUEST ["Name:"];
$message2 =$_REQUEST ["Company:"];
$message3 =$_REQUEST ["Telephone:"];
$message4 =$_REQUEST ["email:"];
$message5 =$_REQUEST ["Reference:"];


$email =$_REQUEST ["email:"];




mail( "info@mydomain.com", "Special Trial Offer Request",
   "Name: $message1\n 
Company: $message2\n 
Telephone: $message3\n 
email: $message4\n 
Reference: $message5\n","from: $email:");
header("Location:http://www.mydomain.com/trialoffer/redir.html" );
?>

 

There might well be a basic error somewhere here, and if there is if someone could let me know it would be much appreciated.  I'm just confused as to why this was working previously and now doesn't seem to respond at all 

 

Many thanks,

 

Laurie

 

 

Link to comment
Share on other sites

Try and set it up using variables, so your mail function looks like:

 

//invoke mail function to send email
mail($toaddress, $subject, $mailcontent, $fromaddress);

 

so when gathering from post try:

 

$name= trim(ucwords($_POST['name']));
$company= trim(ucwords($_POST['company']));
$telephone= trim($_POST['telephone']);
$email= trim($_POST['email']);

$toaddress = your@email.com;
$fromaddress = "From: webserver@example.com";

$subject = "Feedback from web site";

$mailcontent = "<b>Customer Name</b>: ".$name."\n".
                          <b>Customer Company</b>: ".$company."\n".
                          <b>Customer Telephone</b>: ".$telephone."\n".
                          <b>Customer Email</b>: ".$email."\n".

 

 

Link to comment
Share on other sites

Also:

 

1. Put your form inputs' names within quotes in the HTML (i.e.:

 

<input name="Name">

 

).

 

2. Don't put a space between an array name and the key you're trying to access.  In other words, do this:

 

$name = $_REQUEST["Name:"];

 

3. Use the right superglobal array instead of $_REQUEST.  Since you're passing the data in via POST, use $_POST.

 

4. Are you certain that you can mail things out successfully?  Have you tried writing a small test script to see if the mail() function is working at all?

Link to comment
Share on other sites

Ok forgive my stupidity, using the above script I presume the

$toaddress = your@email.com;

line is for whatever email the form will be forwarding to?  Is the email supposed to be like that just as itself, as it doesn't seem to want to forward it to the email.

 

And what sort of short test script should I use to test the mail function? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.