|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hey guys, I need some help! One of the designers I used to have on staff created simple PHP contact forms for several sites. Here is my problem, the PHP sends an email to the designated person, the email that is sent has a “from field” of whatever text I choose. What I need, is for the “from” field to be the email address of the submitter. Can anyone help me out?
[Link deleted by Mod Webnauts] Last edited by Webnauts; 06-15-2007 at 02:19 PM. |
|
||||
|
Something like this
Sign Up Code:
<?php
// Include the MySQL class
require_once('Database/MySQL.php');
// Include the Session class
require_once('Session/Session.php');
// Include the SignUp class
require_once('AccessControl/SignUp.php');
// Include the QuickForm class
require_once ('HTML/QuickForm.php');
// Include the phpmailer class
require_once ('ThirdParty/phpmailer/class.phpmailer.php');
// Settings for MySQL
$host='db.kjellbleivik.com'; // Hostname of MySQL server
$dbUser='******'; // Username for MySQL
$dbPass='******'; // Password for user
$dbName='*****'; // Database name
// Settings for SignUp class
$listener='http://www.kjellbleivik.com/AccessControl/7.php';
$frmName='Kjell Bleivik';
$frmAddress='noreply@kjellbleivik.com';
$subj='Account Confirmation';
$msg=<<<EOD
<h2>Thank you for registering!</h2>
<div>The final step is to confirm
your account by clicking on:</div>
<div><confirm_url/></div>
<div>
<b>Your Site Team</b>
</div>
EOD;
// Instantiate the MySQL class
$db=& new MySQL($host,$dbUser,$dbPass,$dbName);
// Instantiate the Session class
$session=new Session();
// Instantiate the signup class
$signUp=new SignUp($db,$listener,$frmName,$frmAddress,$subj,$msg,TRUE);
// Is this an account confirmation ?
if ( isset ( $_GET['code'] ) ) {
if ( $signUp->confirm($_GET['code']) ) {
$display='Thank you. Your account has now been confirmed.<br />'.
'You can now <a href="4.php">login</a>';
} else {
$display='There was a problem confirming your account.<br />'.
'Please try again or contact the site administrators';
}
// Otherwise display the form
} else {
// Register a session variable for use in the image
if ( !$session->get('randomString') )
$session->set('randomString',$signUp->createRandString());
// A function for comparing password
function cmpPass($element, $confirmPass) {
global $form;
$password = $form->getElementValue('password');
return ($password == $confirmPass);
}
// A function to encrypt the password
function encryptValue($value) {
return md5($value);
}
// Instantiate the QuickForm class
$form =& new HTML_QuickForm('regForm', 'POST');
$renderer =& $form->defaultRenderer();
// Clear the default HTML templates
$renderer->clearAllTemplates();
// Define new templates
$renderer->setFormTemplate('
<table class="registration">
<form{attributes}>{content}
</form>
</table>');
$renderer->setHeaderTemplate('
<tr>
<td class="header" colspan="2">{header}</td>
</tr>');
$renderer->setElementTemplate('
<tr valign="top">
<td class="label">
{label}
</td>
<td class="field">
<!-- BEGIN error --><span class="error">{error}</span><br><!-- END error -->
{element}
<!-- BEGIN required --><span class="required">*</span><!-- END required -->
</td>
</tr>');
$renderer->setRequiredNoteTemplate('
<tr>
<td> </td>
<td class="requiredNote">{requiredNote}</td>
</tr>');
// Add a header to the form
$form->addElement('header', 'header', 'Registration Form');
// Register the compare function
$form->registerRule('compare', 'function', 'cmpPass');
// The login field
$form->addElement('text','login','Desired Username:','class="signupData"');
$form->addRule('login','Please provide a username','required',false,'client');
$form->addRule('login','Username must be at least 6 characters','minlength',6,'client');
$form->addRule('login','Username cannot be more than 50 characters','maxlength',50,'client');
$form->addRule('login','Username can only contain letters and numbers','alphanumeric',NULL,'client');
// The password field
$form->addElement('password','password','Password:','class="signupData"');
$form->addRule('password','Please provide a password','required',false,'client');
$form->addRule('password','Password must be at least 6 characters','minlength',6,'client');
$form->addRule('password','Password cannot be more than 12 characters','maxlength',50,'client');
$form->addRule('password','Password can only contain letters and numbers','alphanumeric',NULL,'client');
// The field for confirming the password
$form->addElement('password','confirmPass','Confirm:','class="signupData"');
$form->addRule('confirmPass','Please confirm password','required',false,'client');
$form->addRule('confirmPass','Passwords must match','compare','function');
// The email field
$form->addElement('text','email','Email Address:','class="signupData"');
$form->addRule('email','Please an email address','required',false,'client');
$form->addRule('email','Please enter a valid email address','email',false,'client');
$form->addRule('email','Email cannot be more than 50 characters','maxlength',50,'client');
// The first name field
$form->addElement('text','firstName','First Name:','class="signupData"');
$form->addRule('firstName','Please enter your first name','required',false,'client');
$form->addRule('firstName','First name cannot be more than 50 characters','maxlength',50,'client');
// The last name field
$form->addElement('text','lastName','Last Name:','class="signupData"');
$form->addRule('lastName','Please enter your last name','required',false,'client');
$form->addRule('lastName','Last name cannot be more than 50 characters','maxlength',50,'client');
// The signature field
$form->addElement('textarea','signature','Signature:','class="signature"');
// The image check field for "humanness"
$form->addElement('text','imageCheck','Image Text:',
'class="signupData"');
$form->addRule('imageCheck','Please enter text from image',
'required',false,'client');
// Server side validation! Don't give away random string in JavaScript
$form->addRule('imageCheck','Please confirm the text in the image',
'regex','/^'.$session->get('randomString').'$/',
'server');
// The image check field
// Changed
$form->addElement('image',
'',
'8.php',
'class="image"');
// Add a submit button called submit and "Send" as the text for the button
$form->addElement('submit','submit','Register','class="createAccount"');
// Specify the "required field" note for the bottom of the form
$form->setRequiredNote('<span class="required">*</span> required');
// If the form is submitted...
if ( $form->validate() ) {
// Apply the encryption filter to the password
$form->applyFilter('password', 'encryptValue');
// Build an array from the submitted form values
$submitVars=array (
'login'=>$form->getSubmitValue('login'),
'password'=>$form->getSubmitValue('password'),
'email'=>$form->getSubmitValue('email'),
'firstName'=>$form->getSubmitValue('firstName'),
'lastName'=>$form->getSubmitValue('lastName'),
'signature'=>$form->getSubmitValue('signature') );
// Create signup
if ( $signUp->createSignup($submitVars) ) {
// Send confirmation email
if ( $signUp->sendConfirmation() ) {
$display='Thank you. Please check your email to '.
'confirm your account';
} else {
$display='Unable to send confirmation email.<br />'.
'Please contact the site administrators';
}
} else {
$display='There was an error creating your account.<br />'.
'Please try again later or '.
'contact the site administrators';
}
} else {
// If not submitted, display the form
$display=$form->toHtml();
}
}
?>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Sign Up </title>
<style type="text/css">
body, a, td, input, textarea
{
font-family: verdana;
font-size: 11px;
}
.registration
{
width: 400px;
}
.header
{
color: navy;
text-align: center;
font-variant: small-caps;
font-size: 15px;
font-weight: bold;
border-color: navy;
border-style: dashed;
border-width: 1px;
background-color: #f6f7f8;
}
.label
{
color: navy;
text-align: right;
width: 40%;
font-weight: bold;
padding: 3px;
}
.info
{
color: navy;
text-align: right;
width: 40%;
padding: 3px;
}
.required
{
color: red;
}
.field
{
width: 60%;
padding: 3px;
}
.error
{
color: red;
}
.requiredNote
{
font-size: 9px;
text-align: right;
}
.signupData
{
width: 200px;
background-color: #f6f7f8;
font-weight: bold;
}
.signature
{
background-color: #f6f7f8;
font-weight: bold;
width: 200px;
height: 100px;
}
.createAccount
{
background-color: #f6f7f8;
color: navy;
font-weight: bold;
}
body {
background-color: #F0F0EC;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<table width="100%" border="0">
<tr height="20%">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="25%"> </td>
<td width="70"><div align="center"><?php echo ( $display );?></div></td>
<td width="5%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
|
|
||||
|
Related:
Code:
<?php
// Include Magic Quotes stripping script
require_once('MagicQuotes/strip_quotes.php');
// Include MySQL class
require_once ('Database/MySQL.php');
// Include Session class
require_once ('Session/Session.php');
// Include Auth class
require_once ('AccessControl/Auth.php');
$host='db.kjellbleivik.com'; // Hostname of MySQL server
$dbUser='******'; // Username for MySQL
$dbPass='******'; // Password for user
$dbName='******'; // Database name
// Instantiate MySQL connection
$db=& new MySQL($host,$dbUser,$dbPass,$dbName);
// Instantiate the Auth class
$auth=& new Auth ($db,'4.php','secret');
// For logging out
if ( isset ( $_GET['action'] ) && $_GET['action'] == 'logout' ) {
$auth->logout();
}
?>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="XHTML namespace">
<head>
<title> Welcome </title>
<meta http-equiv="Content-type"
content="text/html" charset="iso-8859-1" />
<style type="text/css">
body, a, td, input
{
font-family: verdana;
font-size: 11px;
}
h1
{
font-family: verdana;
font-size: 15px;
color: navy
}
</style>
</head>
<body>
<h1>Welcome</h1>
<p>You are now logged in</p>
<?php
if ( isset ($_GET['action']) && $_GET['action'] == 'test' ) {
echo ( '<p>This is a test page. You are still logged in' );
}
?>
<p><a href="../Books/">Implemented code for various Books - Under Construction</a></p>
<p><a href="<?php echo ( $_SERVER['PHP_SELF'] ); ?>?action=logout">Logout</a></p>
</body>
</html>
Code:
<?php
// If $_GET['form'] comes from the Auth class
if ( isset ( $_GET['from'] ) ) {
$target=$_GET['from'];
} else {
// Default URL: usually index.php
$target='5.php';
}
?>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="XHTML namespace">
<head>
<title> Login Form </title>
<meta http-equiv="Content-type"
content="text/html" charset="iso-8859-1" />
<style type="text/css">
body, a, td, input
{
font-family: verdana;
font-size: 11px;
}
h1
{
font-family: verdana;
font-size: 15px;
color: navy
}
</style>
</head>
<body>
<h1>Please log in</h1>
<form action="<?php echo ( $target ); ?>" method="post">
<table>
<tr valign="top">
<td>Login Name:</td>
<td><input type="text" name="login" /></td>
</tr>
<tr valign="top">
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr valign="top">
<td></td>
<td><input type="submit" value=" Login " /></td>
</tr>
</table>
</form>
<a href="..//index.php">Home</a>
</body>
</html>
I think you get the code as soon as you order the books. Download and install it in a few minutes. Note: You should do it professional and secure from the start. Read what Matt Zandstra writes about being too fast. "The problem is that PHP is just too easy. It tempts you to try out your ideas, and flatters you with good results. You write much of your code straight into your Web pages, because PHP is designed to support that. You add the heavier code to functions in library files, and before you know it you have a working Web application. You are well on your way to ruin. You don't realize this, of course, because your site looks fantastic. It performs well, your clients are happy, and your users are spending money."Read more ... |
|
||||
|
Additional information if you use this code.
The first code snippet is 7.php, then 5.php and finally 4.php. In addition, I see that 8.php is also referenced in the code. The code for 8.php is: Code:
<?php
// Include Session class
require_once ('Session/Session.php');
// Include RandomImageText class
require_once ('Images/RandomImageText.php');
// Instantiate the Session class
$session=new Session;
// Instantiate RandomImageText giving the background image
$imageText=new RandomImageText ('reg_image/reg_image.jpg');
// Add the text from the session
$imageText->addText($session->get('randomString'));
// Send the right mime type
header ( 'Content-type: image/jpeg' );
// Display the image
ImageJpeg($imageText->getImage());
?>
The above code is slightly modified from my versions of the book. On their book page sitepoint writes: *Note:Second Edition out soon! PDF version of the 1st Edition only till then. I have the first edition, so may be the code is more compact and better in the second edition. |
|
|||
|
Thanks for all your help guys. I am not a experienced PHP programmer at all! I did get my contact form up and running correctly. I would like to find someone affordable to help with these scripts in the future. I will never really need anything custom, just basic stuff that has already been created, just needs modified for our uses. Can anyone give me a ball park on what it would cost to have a basic contact form script created and implemented on my sites, if I provide the html side of the form?
[Link deleted by Mod Webnauts] Last edited by Webnauts; 06-15-2007 at 02:22 PM. |
|
||||
|
The secure solution I designed above is in the end cut and paste and installing a library. It is done in a few minutes if you know how to.
A simpler solution that is easier to use is PEAR HTML_QuickForm Getting Started Guide If you learn to use HTML_QuickForm, you should be able to make most PHP forms. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |