PHP newb and need help with code

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
Ice2257
Forum Newbie
Posts: 8
Joined: Thu Feb 05, 2009 1:17 pm

PHP newb and need help with code

Post by Ice2257 »

I have php code setup

When someone fills out my form http://www.tacobills.com/form.html

I want the email address field to be the FROM in the email header that I receive

Here is my current php

Code: Select all

<?php
 
//$mail_body = $_POST['submitterName'];
$mail_body .= $_POST['submitterEmail'];
$mail_body .= "\n";
$mail_body .= "\n";
$mail_body .= $_POST['submitterPhone'];
$mail_body .= "\n";
$mail_body .= "\n";
$mail_body .= $_POST['submitterComments'];
 
 
$recipient = 'Ice2257@gmail.com';
$subject = 'You have an order from ' .   $_POST['submitterName'];
 
 
mail($recipient, $subject,$mail_body)
 
header("location: thankyou.html");
 
?>
Last edited by Ice2257 on Thu Feb 05, 2009 1:35 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP newb and need help with code

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: PHP newb and need help with code

Post by mickeyunderscore »

Code: Select all

$from = 'From: ' . $_POST['submitterEmail'];
mail($recipient, $subject,$mail_body,$from);
Ice2257
Forum Newbie
Posts: 8
Joined: Thu Feb 05, 2009 1:17 pm

Re: PHP newb and need help with code

Post by Ice2257 »

Thanks It works Great

Any other ideas you can offer on the code ?

I do not know how to code to make sure all fields are filled out correctly.
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: PHP newb and need help with code

Post by mickeyunderscore »

If you want to check that all of the fields are filled out, then you can use:

Code: Select all

if( ($_POST['submitterEmail']) && ($_POST['submitterPhone']) && ($_POST['submitterComments']) ){
     //send email
}else{
    //form is not filled out fully
}
This uses PHP's 'loose' type comparisons, just to check if something is actually in each field.

You can find more about type comparisons here: http://uk3.php.net/types.comparisons
Ice2257
Forum Newbie
Posts: 8
Joined: Thu Feb 05, 2009 1:17 pm

Re: PHP newb and need help with code

Post by Ice2257 »

Where do I put it ?

Can you provide updated code if possible for me ?
Ice2257
Forum Newbie
Posts: 8
Joined: Thu Feb 05, 2009 1:17 pm

Re: PHP newb and need help with code

Post by Ice2257 »

Is this something easy to do to make sure all the fields are filled out properly ?
Post Reply