|
|
|
|
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.'.';
}
?> | | |
|
| email new items in db Categories : PHP, Email, Databases, MySQL, 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 | | | 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 | | | A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | Encoding data using PGP via PHP's proc_* functions Categories : Cryptography, Security, Email, PHP, PGP | | | Variable serialization and unserialization. Loading and saving variable structures
to and from file. Categories : Arrays, Filesystem, Variables, Strings, PHP | | | PHP MIME Decoder. This class decodes Mime Encoded email message.
Attachments are stored in a director. Works with Multipart/alternative,
multipart/mixed etc.
see http://p3mail.com for example. Categories : PHP, PHP Classes, Email | | | JSON File Upload Categories : PHP, AJAX, Filesystem | | | Current Page's URL using PHP Categories : PHP, Beginner Guides, Global Variables | | | send_mail function to defeat Header Injection Hacking/Spamming Categories : PHP, Email, Form Processing, Security | | | upload function using PHP's FTP abilities. Categories : PHP, Filesystem, HTML and 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
| |
|
|