10 to 20 User Inputs to Process in PHP

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
Rajudk
Forum Newbie
Posts: 6
Joined: Fri Mar 28, 2008 12:48 pm
Location: Orissa

10 to 20 User Inputs to Process in PHP

Post by Rajudk »

I just put my step in PHP.I aim to master it very soon and help others freely.I searched for a Guide to teach me.I bought a book,but the Form Processing Chapters are very limited.So I came here.

My Question: How to process 10 to 20 User inputs(HTML Form inputs) in PHP to send email.(10-20 User Inputs to My Email)
For eg.
Name:
Email:
Tel:
Address1:
Address2:
etc

Pls guide me.I only get free Feedback form for free.I want to add more to it.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Re: 10 to 20 User Inputs to Process in PHP

Post by hawleyjr »

Step 1: create HTML Form
Step 2: Create PHP page to process form. Use either $_POST or $_GET to retrieve the values of the form.
Step 3: Use PHP's native mail() function to send the email.
Rajudk
Forum Newbie
Posts: 6
Joined: Fri Mar 28, 2008 12:48 pm
Location: Orissa

Re: 10 to 20 User Inputs to Process in PHP

Post by Rajudk »

With examples of my user inputs please.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: 10 to 20 User Inputs to Process in PHP

Post by micknc »

If you are looking for the code I would suggest searching for a tutorial. I tried "php mail form tutorial" and got plenty.

This one seemed very simple and would include the framework to get you going:

http://www.kirupa.com/forum/showthread.php?t=17313

The tutorial is self posting but I would adapt it like hawleyjr said to go from the form page to a process page.
Rajudk
Forum Newbie
Posts: 6
Joined: Fri Mar 28, 2008 12:48 pm
Location: Orissa

Re: 10 to 20 User Inputs to Process in PHP

Post by Rajudk »

Thanks Kirupa.com.
Can you suggest me of a Secure PHP to email Hot Script that is compitabble with Php v.5.2.3.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: 10 to 20 User Inputs to Process in PHP

Post by micknc »

I use SwiftMailer. It is compatible and can use (among others) SMTP.

http://www.swiftmailer.org/
Rajudk
Forum Newbie
Posts: 6
Joined: Fri Mar 28, 2008 12:48 pm
Location: Orissa

Re: 10 to 20 User Inputs to Process in PHP

Post by Rajudk »

It did not work,a little guidance please.Write here by changing the codes below-
Can any one make the following a valid php5 form processing:-

<?php

$_POST['fullname']
$_POST['email']
$_POST['telephone']
$_POST['mobile']
$_POST['plan']
$_POST['agreement'] // user input will be yes or no


$to = $_POST[email];
$sublect = "We'll reply very soon";
$msg = "Dear: " . $_POST[fullname] . " " $_POST[email] . ",\n\n";
$msg .= "We have received details from you."

$mailheaders = "From: Registration Page <aaaa@ppp.com>;
$mailheaders .= "Reply - To: dddd@eee.com";

mail($to, $subject, $msg, $mailheaders);


?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: 10 to 20 User Inputs to Process in PHP

Post by John Cartwright »

Code: Select all

$msg .= "We have received details from you."
You are missing a semi colon. Disreguarding the security implications of your script (using unsanitized input) and potentially firing off E_NOTICE errors from undefined variables, and E_NOTICE undefined constants from not quoting array keys, things look ok.

Try putting error_reporting(E_ALL); at the top of your script and see the magic happen :)

However, I would have to kindly ask you to stop asking people to do the work for you. This includes PM's.
Rajudk
Forum Newbie
Posts: 6
Joined: Fri Mar 28, 2008 12:48 pm
Location: Orissa

Re: 10 to 20 User Inputs to Process in PHP

Post by Rajudk »

See there is Parse error: syntax error,
unexpected T_STRING in /nnnn/hhhh/public_html/present.php
on line 9 (which is underlined).

Any other errors and Security issue?

<?php

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email']))
{ header( "Location: $formurl="http://www.pppp.com/form5.html" ); exit ;
}
if (empty($name) || empty($email) || empty($comments)) { header(
"Location: $errorurl="http://www.pppp.com/error.html" ); exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) { header(
"Location: $errorurl="http://www.pppp.com/error.html" ); exit ;
}
if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments );
}
$messageproper = "This message was sent from:\n" . "$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" . "Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto='bikri@pppp.com', $subject="Feedback Form", $messageproper, "From: \"$name\"
<$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
$headersep . "X-Mailer:php 5.2.3" );
header( "Location: $thankyouurl="http://www.pppp.com/success.html" );
exit ;

?>
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: 10 to 20 User Inputs to Process in PHP

Post by EverLearning »

Code: Select all

 
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email']))
{ header( "Location: $formurl="http://www.pppp.com/form5.html" ); exit ;
}
if (empty($name) || empty($email) || empty($comments)) { header(
"Location: $errorurl="http://www.pppp.com/error.html" ); exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) { header(
"Location: $errorurl="http://www.pppp.com/error.html" ); exit ;
}
if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments );
}
$messageproper = "This message was sent from:\n" . "$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" . "Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto='bikri@pppp.com', $subject="Feedback Form", $messageproper, "From: \"$name\"
<$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
$headersep . "X-Mailer:php 5.2.3" );
header( "Location: $thankyouurl="http://www.pppp.com/success.html" );
exit ;
If you had put your code in proper tags(like above), you would have seen the problem yourself.
Which is, in case you still don't see it, in your header() arguments.

So ...
1. If you're going to use double quotes (") in a string that is double quoted you have to escape them (\"), or simpler, use single quotes('). That unexpected string error happened because PHP parser encountered http://www.pppp.com/form5.html after the end of the string.
2. You can't define variables in strings like you tried.

Code: Select all

header( "Location: $formurl="http://www.pppp.com/form5.html" ); exit ;
should be

Code: Select all

$formurl="http://www.pppp.com/form5.html";
header( "Location: $formurl" );
exit;
You really should read more on PHP basics. Read around the forums, use Google.
Post Reply