Php > Databases
This script is a contact form between users of a website
This script is a contact form between users of a website (kinda like the PM function on the forums) "; $email = ''; } //sender's email if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $your_email)) { $err_msg .= "Your email is not valid. Please re-enter it
"; $your_email = ''; } //check to see if the other elements have values if(empty($message)) { $err_msg .= "No message set. Please enter a message.
"; } if(empty($subject)) { $err_msg .= "No subject set. Please enter a subject.
"; } if(empty($your_name)) { $err_msg .= "No sender name set. Please enter a your name.
"; } //check the err_msg to see if there are any messages if ($err_msg != ''){ //there is an error so build the data into a pipe delimited string and pass it back to the form $data = "$email|$subject|$message|$your_email|$your_name"; show_form($data,$err_msg); die(); }//end if //send the email //build the headers $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "X-Priority: 1\n"; $headers .= "X-MSMail-Priority: High\n"; $headers .= "X-Mailer: PHP\n"; $headers .= "From: \"".$your_name."\" <".$your_email.">\n"; if (!mail($email, $subject, $message, $headers)) { echo "Email failed!"; }else{ echo ""; }//end if }//end function /* show_form function*/ function show_form($data='',$msg='') { //show the form for the email //the $data='' and $msg='' constructs allow for no information to be passed to the function //set defaults for function $subject = ''; $email = ''; $message = ''; $your_name = ''; $your_email = ''; //explode the string passed back from the send_mail function if there is an error if (($data !="" )&&($msg != "")) { $elements = explode("|",$data); $email = $elements[0]; $subject = $elements[1]; $message = $elements[2]; $your_email = $elements[3]; $your_name = $elements[4]; }//end if /* optional where clauses could include: 1. only active users 2. check to see if the user wants to allow contact from others on the site 3. only new users (signed up within a certain date) */ $sql = "select email_address from tablename [optional where clause]"; //your db connection stuff goes here $result = mysql_query($sql); echo "
Email A Friend
"; echo "
"; echo "
"; echo "
Email A Friend
"; echo "
"; echo "
$msg
"; //produce the email drop down if (($result)&&(mysql_num_rows($result)>0)){ //produce the drop down list echo "
Email Address:
"; //optionally add MULTIPLE to allow sending to multiple addresses while ($rows = mysql_fetch_array($result)){ echo "
".$rows['email_address']."
"; }//end while echo "
"; }else{ //if there is a problem, have the user manually enter the email address echo "
Currently unable to locate email addresses. There maybe a problem with the database.
"; echo "
"; echo "
Please enter the email address manually
"; echo "
Email Address:
"; }//end if echo "
Subject:
"; echo "
Message:
$message
"; echo "
Your name:
"; echo "
Your Email:
"; echo "
"; echo "
"; }//end function ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage