WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem Click here to Update Your Picture
Christian Haensel
Date : Jun 14th 2007
Grade : 2 of 5 (graded 6 times)
Viewed : 20144
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Christian Haensel
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

<?
/* PHP based Contact form with multiple recipients. Receipients are loaded from a text file.
The script uses the PHP mail() function.

Programmed by Christian Haensel, christian@chftp.com, LINK1http://www.chftp.comLINK1
Exclusively published on weberdev.com. If you like my scripts, please let me know or link to me.

You may copy, redistirubte, change and alter my scripts as long as this information remains intact
*/
// The file containing the contact information
// Data line layout:
// Number;Name;Email;department
// like Christian Haensel;christian@chftp.com;Webdesign
$rec_file    =    "contacts.txt";
$rec    =    file($rec_file);

function
getContacts($rec) {
    foreach(
$rec as $line) {
        list(
$cnumber, $cname, $cemail, $cdept) = split(";", $line);
        echo
'<option value="'.$cnumber.'">'.$cdept.' -> '.$cname.'</option>'."\n";
    }
}


// Form output if user is not sending
if(!isset($_POST['do'])) {
    echo
'
    <b>Select a contact</b><p>
    <form name="contact" method="post" action="'
.$PHP_SELF.'">
    <select name="contacts">'
;
   
getContacts($rec);
    echo
'</select>
    <br />
    <b>Your name:</b><br><input type="text" name="sender"><br>
    <b>Your Email:</b><br><input type="text" name="email"><br>
    <b>Your message:</b><br><textarea name="message"></textarea><br>
    <input type="hidden" name="do" value="sendmail">
    <input type="submit" value="Send" />
    </form>'
;

} else {
   
// Get Contact Details from textfile
   
foreach($rec as $line) {
       
$number    =    $_POST['contacts'];
        list(
$cnumber, $cname, $cemail, $cdept) = split(";", $line);
        if(
$cnumber == $number) {
           
$contname    =    $cname;
           
$contemail    =    $cemail;
        }
    }
   
// Send the email
   
$sender_name    =    $_POST['sender'];
   
$sender_email    =    $_POST['email'];
   
$sender_msg        =    $_POST['message'];
   
$headers = "From: ".$sender_name." <".$sender_email."> \r\n";
   
$headers.= "Content-Type: text/plain; charset=ISO-8859-1 ";
   
$headers .= "MIME-Version: 1.0 ";
   
$email_subject    =    "New message from ".$sender_name;
   
$mail_text        =    '
    Hello '
.$contname.'
   
    '
.$sender_name.' is sending you the following message:
    ----------------------------------------------------------
    '
.$sender_msg.'
    ----------------------------------------------------------
    The sender email address is '
.$sender_email;
   
   
mail($contemail, $email_subject, $mail_text, $headers);
    echo
'<b>Thank you!</b><p>Your message has been sent to '.$contemail.'.';
}
?>



Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
Selecting a random line from a text file
Categories : PHP, Filesystem, Arrays, Beginner Guides
Email attachment code
Categories : PHP, Email, Filesystem
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
PHP port of Matt Wrights FormMail.pl WWW form to e-mail gateway.
Categories : Email, Complete Programs, Environment Variables, PHP
Form Validation Using PHP to highlight non valid fields
Categories : PHP, Form Processing, Data Validation, Beginner Guides
HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP
PHP Image Validation Class - test if a specific file is of a certain image type without relying on the said file extension.
Categories : PHP, PHP Classes, Data Validation, Graphics, Beginner Guides
EAvalidator - This class can be used to validate an e-mail address by checking its domain.
Categories : PHP, PHP Classes, Email, Regexps
Simple Cookie example
Categories : PHP, Beginner Guides, Cookies
 Vincent Weber wrote :1759
Hey!

I was checking your code and was wondering how the textfile has to looks like..because i got this error while running in the webbrowser IE. In other words can I use this form directly or do I need to create this contacts.txt by myself and how??

(im just beginning with php..)

greets Vin