homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Having trouble with a php form to mail script
Keep getting blank messages from web based email form

10+ Year Member

Msg#: 3875319 posted 5:04 pm on Mar 20, 2009 (gmt 0)


I just created a new mail form in Dreamweaver. I am still quite green with php. Im working on a form to mail script that I cant 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:

$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:

<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" />

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:

<form id="formEmail" name="formEmail" method="post" action="sendmail2.php">
<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 />
<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>
<br />
<p> How long have u been sawing?</p>
<input type="radio" name="WoodLength" value="newbie" id="WoodLength_0" tabindex="70" />
0-2 years</label>
<br />
<input type="radio" name="WoodLength" value="novice" id="WoodLength_1" tabindex="80" />
3-5 years</label></td>
<br />
<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 />

and when I use it with the associated sendmail2.php script:

<?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 get through - just a blank email sent to my address. Can anyone point me in the right direction what am I doing wrong?

Note: That password field is not really a login password, I just wanted to use it for testing purposes.

Do I have to refrence the type and id attributes in the php script as well?

Thanks for any input.



10+ Year Member

Msg#: 3875319 posted 12:22 am on Mar 23, 2009 (gmt 0)

You need to adjust the mail function line as you havent updated it to work correctly with the new form to include its field data, first you would want to compile your data into one message i.e.

// \n inside "" to start a new line, formats your email
$_SERVER['newEmailMessage'] ='Password: '.$pwd."\n";
// .= here will append the data to the existing in the given variable
$_SERVER['newEmailMessage'].='Confirm: '.$confirm."\n";
$_SERVER['newEmailMessage'].='First name: '.$firstname."\n";
$_SERVER['newEmailMessage'].='Last Name: '.$lastname."\n";
$_SERVER['newEmailMessage'].='Region: '.$region."\n";
$_SERVER['newEmailMessage'].='WoodLength: '.$WoodLength."\n";

and so on until you have all your data in one variable, formatted as required ( i could be wrong but i recall something about 80 chars per line in emails, anyone care to elaborate), then amend the mail function as follows:

mail("help@mydomain.com", "Feedback Form Results", $_SERVER['newEmailMessage'], "From: ".$emailAddress);

Just incase i would house the mail function in an if statement to check the result, that way if there is an error you can catch it and display a friendly message:

if(!mail( [code here] )){
echo "Failed";
echo "Sent";


10+ Year Member

Msg#: 3875319 posted 12:29 am on Mar 23, 2009 (gmt 0)

This code will work with your form, if you want to check the data uncomment the post and exit lines.



$emailAddress = $_REQUEST['emailAddress'];
$_SERVER['newEmailMessage'] .= $_REQUEST['pwd']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['confirm']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['firstname']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['lastname']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['region']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['WoodLength']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['shop']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['tools']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['saws']."\n";
$_SERVER['newEmailMessage'] .= $_REQUEST['Comments']."\n";

//echo $_SERVER['newEmailMessage'];

if( !mail( "help@mydomain.com", "Feedback Form Results", $_SERVER['newEmailMessage'], "From: ".$emailAddress ) ){
header( "Location: failed.html" );
header( "Location: thankyou.html" );

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved