e-mail 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
achisholm
Forum Newbie
Posts: 2
Joined: Mon Mar 26, 2007 8:45 am

e-mail form

Post by achisholm »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, I've created an email form on my website by following a guide. I now have two files:

contact.htm...
[syntax="html"]<form method=post action="sendmail.php">
  <table width="691" border="0" cellpadding="5" cellspacing="0">
    <tr>
        <td width="185" class="white">
        <p align="left">your name:</p>        </td>
        <td width="29">&nbsp;</td>
        <td width="447"><input name="name" type="text" size="40" />        </td>
    </tr>
    <tr>
        <td class="white">
        <p align="left">your email address:</p>        </td>
        <td>&nbsp;</td>
        <td><input name="email" type="text" size="40" />        </td>
    </tr>
    <tr>
	<tr>
        <td class="white">
        <p align="left">your phone number:</p>        </td>
        <td>&nbsp;</td>
        <td><input name="phoneNumber" type="text" size="40" />        </td>
    </tr>
    <tr>
        <td valign="top" class="white"><p align="left">best time to contact you?</p>        </td>
        <td valign="top">&nbsp;</td>
        <td valign="top">
            <select name="bestTime">
				<option value="none" selected="selected">please select...</option>
                <option value="Weekday morning">weekday morning</option>
                <option value="Weekday afternoon">weekday afternoon</option>
                <option value="Weekend">weekend</option>
                <option value="Any time">any time</option>
        </select>      </td>
    </tr>
	    <tr>
        <td valign="top" class="white"><p align="left">preferred method of contact?</p>        </td>
        <td valign="top">&nbsp;</td>
        <td valign="top">
            <select name="contactMethod">
				<option value="none">please select...</option>
                <option value="email">by email</option>
                <option value="phone">by phone</option>
            </select>      </td>
    </tr>  
    <tr>
        <td valign="top" class="white">
        <p align="left">please enter your questions<br /> 
        or comments below:</p>        </td>
        <td>&nbsp;</td>
        <td><textarea name="message" rows="5" cols="50"></textarea>        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td></td>
        <td><input name="submit" type="submit" value="Click to Send" /></td>
    </tr>
    </table>
  <div align="right"></div>
</form>
and Sendmail.php...[/syntax]

Code: Select all

<?php

mail("info@mydomainname.co.uk", "From your Contact Form...", $_REQUEST[message], "From: $_REQUEST[email]", "-f".$_REQUEST[email]);

header( "Location: http://www.mydomainname.co.uk/thankyou.htm" );

?>
It is actually working fine although when I receive the email it doesn't include all of the information. It only includes the contents of the "message" field. Can you help me so that i will be recieving all the information in the received email?

Kind regards,
Alistair


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

This call:

Code: Select all

mail("info@mydomainname.co.uk", "From your Contact Form...", $_REQUEST[message], "From: $_REQUEST[email]", "-f".$_REQUEST[email]);
indicates what you want to send. The third parameter is the message body and you're just passing $_REQUEST[message] here.

NOTE: You should be using

Code: Select all

$_REQUEST['message']
If you want to send all he form info, just create a new variable $body or such like and concatenate it all into the string.
achisholm
Forum Newbie
Posts: 2
Joined: Mon Mar 26, 2007 8:45 am

Post by achisholm »

thanks a lot. I understand what i have to do here although i am not entirely sure of the way to create the $body variable.

Would you be able to give me some advice on this?
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

All the fields from your form are contained in an array called $_POST (better to use that than $_REQUEST)

If you are just sending a text email rather than html, then you need to do what Feyd said and concatenate the data.

Code: Select all

$body=$_POST['phoneNumber']."\n".$_POST['nextformfield']."\n".$_POST['andthenextone'];
The dot concatenates the string - appends the next bit.
The \n puts a newline in.

Is your form public? You are in great danger of helping spammers if you don't verify that the email address entered contains only an email address - spammers add a bunch of stuff that inject new headers and grilled spam into your message
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Did I blank on a post I made?

;)
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Noooo! Sorry, just assumed it was you as devnet's most prolific helper!

Of course you'd have picked up on the $_REQUEST thing!!!!

d11wtq - was that your first motor?
Post Reply