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