WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : 3 of 5 (graded 2 times)
Viewed : 7361
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

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

<?
/* 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.'.';
}
?>



Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
Simple image counter
Categories : PHP, Graphics, Filesystem, Beginner Guides
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
Keep() - maintenance function for backup folders
Categories : PHP, Filesystem, Maintenance
Find the day of the week for any given year/month/day.
Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides
Solution to those 'tell-a-friend' type email issues
Categories : PHP, Email, Databases, MySQL
Contents Page - a script to build contents pages.
Categories : Complete Programs, PHP, Utilities, Filesystem
Upload Via FTP - an alternative to move_uploaded_file
Categories : PHP, FTP, Beginner Guides
PHP and javascript mouseover, mouseout, and mousedown events
Categories : PHP, Java Script, Form Processing, Beginner Guides
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Display list of files within current and subdirectories (recursively) showing each file as an anchored link and each directory as a category header.
Categories : Filesystem, Directories, Arrays, PHP
 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