function SendOffer( $first_name, $last_name, $email_address, $subject, $offer, $format, $headers, $encoding ) {
global $return_path_addr, $script_name, $script_version;
// $offer -> The offer full name with extention
// $format -> The message format, 'html' or 'text' so we can set the headers accordingly
$filename = "post_sale_offers/" . $offer;
if ( file_exists( $filename ) && stristr( $email_address, "@" ) !== FALSE ) {
$filehandle = fopen($filename, "r");
if ($filehandle) {
$message = "";
while (!feof($filehandle)) {
$message .= fgets($filehandle, 4096);
}
fclose($filehandle);
$message = str_replace( "\r", "\r\n", $message ); // Replace all '\r' with '\r\n' in $message
$key = strtoupper( md5( uniqid( microtime() ) ) );
$key = substr( $key, 1, 8 ) . "-" . substr( $key, 9, 4 ) . "-" . substr( $key, 13, 4 ) . "-" . substr( $key, 17, 4 ) . "-" . substr( $key, 20, 12 );
$host = getthehostname( $_SERVER['HTTP_HOST'] );
$messageid = "<" . $key . "@" . $host . ">";
$temp = $headers;
$headers = "Return-Path: $return_path_addr\r\n";
$headers .= "Message-ID: $messageid\r\n";
$headers .= "Mime-Version: 1.0\r\n";
$headers .= $temp . "\r\n";
$headers .= "Date: " . date( DATE_RFC822 ) . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n"; //$script_name/$script_version\r\n";
if ( $encoding <> "" ) {
if ( $format == "html" ) {
$headers .= "Content-Type: text/html; charset=$encoding\r\n";
} else {
$headers .= "Content-Type: text/plain; charset=$encoding; Format=flowed\r\n";
}
$headers .= "Content-Transfer-Encoding: 8bit";
} else {
//if ( $format == "html" ) {
//$headers .= "Content-Type: text/html; charset=us-ascii\r\n";
//} else {
//$headers .= "Content-Type: text/plain; charset=us-ascii; Format=flowed\r\n";
//}
//$headers .= "Content-Transfer-Encoding: 7bit";
}
$full_address = "$first_name $last_name <$email_address>";
$result = @mail($full_address, $subject, $message, $headers);
if ( !$result ) { LogDeliveryError($full_address, $subject, $message, $headers); }
}
}
}