Trouble with a form to mail script for web email form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nadsab
Forum Newbie
Posts: 2
Joined: Fri Mar 20, 2009 12:44 pm

Trouble with a form to mail script for web email form

Post by nadsab »

Hi,

I just created a new mail form in Dreamweaver. I am still quite green with php. I’m working on a feedback form script that I can’t seem to get right.

Here is the problem. When I run this little test script (named sendmail2.php) on my server just to make sure PHP is working OK for web email forms:

Code: Select all

 
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "help@mydomain.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.mydomain.com/thankyou.html" );
?> 
 
Which takes input from the following testmail.html page form:

Code: Select all

<form method="post" action="sendmail2.php">
 Email: <input name="email" type="text" /><br />
 Message:<br />
 <textarea name="message" rows="15" cols="40">
 </textarea><br />
 <input type="submit" />
</form>
It works great, I get the senders email address and comment sent to my email address – account.

But the form I want to use my final design from Dreamweaver, is:

Code: Select all

<form id="formEmail" name="formEmail" method="post" action="sendmail2.php">
 <fieldset>
  <legend>Account Info:</legend>
   <label for="emailAddress">User Name:</label>
  <input type="text" name="emailAddress" id="emailAddress" tabindex="10" />
 <br />
   <label for="pwd">Password</label>
  <input type="text" name="pwd" id="pwd" tabindex="20" />
 <br />
   <label for="confirm">Confirm Password:</label>
  <input type="text" name="confirm" id="confirm" tabindex="30" />
 <br />
 </fieldset>
 <fieldset>
 <legend>Personal Info</legend>
 <br />
  <label for="firstname">First Name:</label>
  <input type="text" name="firstname" id="firstname" tabindex="40" />
 <br />
 <br />
  <label for="lastname">Last Name:</label>
  <input type="text" name="lastname" id="lastname" tabindex="50" />
 <br />
 <br />
  <label for="region">What state do you live in?</label>
  <select name="region" id="region" tabindex="60">
<option value="al">Alabama</option>
  <option value="in">Indiana</option>
  <option value="mich" selected="selected">Michigan</option>
  <option value="oh">Ohio</option>
  </select>
 <br />
 <p> How long have u been sawing?</p>
   <label>
  <input type="radio" name="WoodLength" value="newbie" id="WoodLength_0" tabindex="70" />
  0-2 years</label>
  <br />
   <label>
  <input type="radio" name="WoodLength" value="novice" id="WoodLength_1" tabindex="80" />
  3-5 years</label></td>
  <br />
   <label>
  <input type="radio" name="WoodLength" value="expert" id="WoodLength_2" tabindex="90"/>
  6 plus years</label><br />
  <p>What tools do you use most often?</p>
 <br />
  <input type="checkbox" name="shop" id="shop" tabindex="100" />
  <label for="shop">Shopping</label>
 <br />
   <input type="checkbox" name="tools" id="tools" tabindex="120" />
  <label for="tools">Tools</label>
 <br />
   <input type="checkbox" name="saws" id="saws" tabindex="130" />
  <label for="saws">Saws</label>
 <br />
 
  <label for="Comments">Additional Comments</label>
  <br />
  <textarea name="Comments" id="Comments" cols="50" rows="10" tabindex="140"></textarea>
  <br />
  <input type="submit" name="submit" id="Submit" value="Join Mail List" tabindex="160" />
 <br />
  </fieldset>
 </form>
 
…and when I use it with the associated sendmail2.php script:

Code: Select all

 
<?php /*?>
<?php
$emailAddress = $_REQUEST['emailAddress'] ;
$pwd = $_REQUEST['pwd'] ;
$confirm = $_REQUEST['confirm'] ;
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$region = $_REQUEST['region'] ;
$WoodLength = $_REQUEST['WoodLength'] ;
$shop = $_REQUEST['shop'] ;
$tools = $_REQUEST['tools'] ;
$saws = $_REQUEST['saws'] ;
$Comments = $_REQUEST['Comments'] ;
mail( "help@mydomain.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.mydomain.com/thankyou.html" );
?>
 
The email is received, but with a blank return email address and an empty message. None of the comments or form values. Can anyone point me in the right direction – what am I doing wrong?

Thanks for any input.
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: Trouble with a form to mail script for web email form

Post by Inkyskin »

You need to put your values into the $message value:

Code: Select all

 
$emailAddress = $_REQUEST['emailAddress'] ;
$pwd = $_REQUEST['pwd'] ;
$confirm = $_REQUEST['confirm'] ;
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$region = $_REQUEST['region'] ;
$WoodLength = $_REQUEST['WoodLength'] ;
$shop = $_REQUEST['shop'] ;
$tools = $_REQUEST['tools'] ;
$saws = $_REQUEST['saws'] ;
$Comments = $_REQUEST['Comments'] ;
 
// Like this, only you'll need them all
 
$message = '
First name: '.$firstname.'
Last Name: '.$lastname.'
';
 
// Also, you need to set the correct variable for the email address, like so
 
mail( "help@mydomain.com", "Feedback Form Results",
$message, "From: $emailAddress" );
header( "Location: http://www.mydomain.com/thankyou.html" );
 
// This helps with those on older (and maybe newer) safari browsers on the Mac after a redirect:
 
exit();
 
 
nadsab
Forum Newbie
Posts: 2
Joined: Fri Mar 20, 2009 12:44 pm

Re: Trouble with a form to mail script for web email form

Post by nadsab »

Thanks so much!

Do you mean like this – add this below to the top (or bottom) of the script, while leaving the first part
as is?

Code: Select all

$message = '
User Name: '.$emailAddress.'
Password: ‘.$pwd.’
Confirm Password: ‘.$confirm.’
First Name: '.$ firstname.'
Last Name: '.$lastname.'
What State Do You Live In: ‘.$region.’
Shopping: ‘.$shop.’
Tools: ‘.$tools.’
Saws: ‘.$saws.’
Additional Comments: ‘.$comments.’
Also, how would I do the radio buttons? I’m a bit confused on that, also not sure if I got the check boxes right either for that matter……

For the radio buttons, how would I associate the chosen value to WoodLength? Or do I not need to do that? Did I get it right?

And so I understand, I need to add exit(); to the end of the script, for mac’s?
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: Trouble with a form to mail script for web email form

Post by Inkyskin »

On a lot of Mac machines, I've noticed that if you don't put the exit() after a header redirect, you often get left with a blank white page, rather than the actual redirect.
Post Reply