Chris
I stole this from an OS project called "Dandra Dev Snippets" - check SourceForge.net - the filename is sendmail.php and as you will see it's a couple of years old (No idea how long it's sat on my system - so it has probably been updated)
Code:
<?php /* (c) Copyright 2000,2001, Stefan Morgenroth, dandra.network, http://dandra.org */
// $Id: sendmail.php,v 1.4 2001/11/04 23:29:53 dandra Exp $ , $Revision: 1.4 $
/****************************************************************************
*
* sendmail - sending e-mails through a HTML formular
*
***************************************************************************/
/**
* The following values should be submited by the HTML form
* or will be fixed by removing the comment trailing the concerning line
**/
// $maildomain = 'domain.org';
// $recipient = 'contact';
// $mailsubject = '';
// $mailmessage = '';
// $lastname = '';
// $firstname = '';
// $email = '';
// $company = '';
// $priority = 3; // e-mail priority: 1: High, 3: Normal, 5: Low
$thankspageurl = 'http://www.domain.org/thanks.html';
// Text of error message
$alerterror = 'You forgot:';
$alerterror_missingfirstname = 'your first name!';
$alerterror_missinglastname = 'your last name!';
$alerterror_wrongemail = 'your valid e-mail address!';
$str_back = 'Back to last page';
//**** CHANGE THIS IF YOU WANT TO CHANGE THE MAIL RECIPIENTS ****//
// for eg. contact@domain.org
$targetuser[0] = 'contact'; // default recipient user
$targetuser[1] = 'contact';
$targetuser[2] = 'investors';
$targetuser[3] = 'postmaster';
$targetuser[4] = 'webmaster';
$targetuser[5] = 'admin';
//*********** DO NOT EDIT BEHIND THIS LINE ******************//
/* recipients */
/* to create multirecipient:
$recipient_mail .= "Mary <mary@u.college.edu>" . ", " ; // note the comma!
$recipient_mail .= "Kelly <kelly@u.college.edu>" . ", ";
$recipient_mail .= "anton@domain.org";
*/
// Build e-mail out of the recipient keyword
$recipient_mail == '';
if ($recipient != '')
{
switch ($recipient)
{
case $targetuser[1]: // e.g. mail to contact@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[2]: // e.g. mail to investors@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[3]: // e.g. mail to postmaster@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[4]: // e.g. mail to webmaster@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
case $targetuser[5]: // e.g. mail to admin@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
break;
default:
{
$recipient = $targetuser[0]; // mail to contact@domain.org
$recipient_mail = '"'.$recipient.'" <'.$recipient.'@'.$maildomain.'>';
}
}
}
/* subject */
// $subject = "Birthday Reminders for August";
// Build a structured subject
$subject = $maildomain.' > '.$recipient.' > '.substr($mailsubject, 0, 20);
/* message */
// Build the complex mailbody
/*
$message .= "The following email includes a formatted ASCII table\n";
$message .= "Day \t\tMonth \t\tYear\n";
$message .= "3rd \t\tAug \t\t1970\n";
$message .= "17rd\t\tAug \t\t1973\n";
*/
$message = '';
$message .= "\n";
$message .= $mailmessage;
$message .= "\n\n";
/* you can add a special signature */
/*
$message .= "--\r\n"; //Signature delimiter
$message .= "Birthday reminder copylefted by public domain";
*/
$message .= "___________________________\r\n"; //Signature delimiter
$message .= "dandra.sendertracking\r\n";
$message .= 'Referrer: '.getenv('HTTP_REFERER')."\n";
$message .= 'Browser: '.getenv('HTTP_USER_AGENT')."\n";
$message .= "RemoteAddr: ".getenv('REMOTE_ADDR');
$message .= "\t RemoteHost: ".getenv('REMOTE_HOST')."\n";
/* additional header pieces for errors, From cc's, bcc's, etc */
/*
$headers = "From: contact@domain.org"; // From to
$headers .= "cc: webmaster@domain.org\n"; // CC to
$headers .= "bcc: postmaster@domain.org, admin@php.net\n"; // BCCs to
$headers .= "X-Sender: <sender@anotherdomain.org>\n";
$headers .= "X-Mailer: dandra.network.mailer\n"; // mailer
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: <birthday@php.net>\n"; // Return path for errors
*/
/*
*/
if (($lastname != '') && ($firstname != '') && (($email != '') && ((strpos($email, '@') >= 2) && (strrpos($email, '.') >= 4))))
{
$sender_email = $email;
$headers = '';
$headers .= 'From: "'.$lastname.', '.$firstname.', '.$company.'" <'.$sender_email.'>'."\n";
// $headers .= 'Cc: "'.$name.', '.$vorname.', '.$firma.'" <'.$sender_email.'>'."\n";
// $headers .= 'Bcc: "'.$name.', '.$vorname.', '.$firma.'" <'.$sender_email.'>'."\n";
$headers .= "X-Sender: <".$sender_email.">\n";
$headers .= "X-Mailer: dandra.network.mailer.PHP".phpversion()."\n"; // mailer ID
$headers .= "User-Agent: ".getenv('HTTP_USER_AGENT')."\n";
/*
// Priority Level for the e-mail
X-Priority: 1
X-MSMail-Priority: High
X-Priority: 3
X-MSMail-Priority: Normal
X-Priority: 5
X-MSMail-Priority: Low
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
*/
switch ($priority)
{
case 1:
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
break;
case 3:
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
break;
case 5:
$headers .= "X-Priority: 5\n";
$headers .= "X-MSMail-Priority: Low\n";
break;
default:
{
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
}
}
$headers .= "Return-Path: <".$sender_email.">\n"; // Return path for errors
/* If you want to send html mail, uncomment the following line */
// $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type
/* and now mail it */
// mail($recipient, $subject, $message, $headers);
if ($recipient_mail != '')
{
// mail($recipient_mail, $subject, $message, $headers);
if (mail($recipient_mail, $subject, $message, $headers))
{
header('Location: '.$thankspageurl);
}
}
}
else
{
$alerterror_out = '';
echo '<script language="JavaScript">';
$alerterror_out .= $alerterror.' ';
echo "alert(' ".$alerterror_out;
if ($lastname == '')
{
// $alerterror_out .= $alerterror_missinglastname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missinglastname.' ';
}
if ($firstname == '')
{
// $alerterror_out .= $alerterror_missingfirstname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missingfirstname.' ';
}
if ((strpos($email, '@') < 2) && (strrpos($email, '.') < 4))
{
// $alerterror_out .= $alerterror_wrongemail;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_wrongemail.' ';
}
echo " ');";
// echo "alert(' ".$alerterror_out." ');";
echo 'history.back();';
echo '</script>';
echo '<noscript>';
echo '<h2>'.$alerterror_out;
if ($lastname == '')
{
// $alerterror_out .= $alerterror_missinglastname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missinglastname.' ';
}
if ($firstname == '')
{
// $alerterror_out .= $alerterror_missingfirstname;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_missingfirstname.' ';
}
if ((strpos($email, '@') < 2) && (strrpos($email, '.') < 4))
{
// $alerterror_out .= $alerterror_wrongemail;
// $alerterror_out .= $alerterror_out.' ';
echo $alerterror_wrongemail.' ';
}
echo '</h2>';
echo '<h3><a href="'.$HTTP_REFERER.'" title="'.$str_back.'">'.$str_back.'</a></h3>';
echo '</noscript>';
}
Bookmarks