// 3 usefull & working headers function socketmail($from, $replyto, $rcpt_email, $subject, $message, $content_type) { GLOBAL $site_variables; $hostname=str_replace('http://','',$site_variables['url']); if (empty($hostname)) { error_gui('Invalid "url" in site_variables'); } if ( (empty($from)) || (empty($replyto)) || (empty($rcpt_email)) || (empty($subject)) || (empty($message)) || (empty($content_type)) ){ error_gui('malformed socketmail request!'); } $message = str_replace("\n", "\r\n", stripslashes($message)); ini_set('sendmail_from', $replyto); $connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30) or die("Could not talk to the sendmail server!"); $rcv = fgets($connect, 1024); // $rcv = fgets($connect, 1024); $counter = 0; // foreach ($to_array as $rcpt_email) { /////// $rcpt_email = trim($rcpt_email); // if (!validate_email_address($rcpt_email)) // continue; fputs($connect, "EHLO $hostname\r\n"); // fputs($connect, "EHLO\r\n"); fputs($connect, "MAIL FROM: $replyto\r\n"); $rcv = fgets($connect, 1024); fputs($connect, "RCPT TO: $rcpt_email\r\n"); $rcv = fgets($connect, 1024); fputs($connect, "DATA\r\n"); $rcv = fgets($connect, 1024); fputs($connect, "From: $from <$replyto>\r\n"); fputs($connect, "To: <$rcpt_email>\r\n"); // fputs($connect, "X-Sender: <$replyto>\r\n"); fputs($connect, "Return-Path: <$replyto>\r\n"); fputs($connect, "Errors-To: <$replyto>\r\n"); // fputs($connect, "Importance: normal\r\n"); fputs($connect, "X-Mailer: PHP 5.2\r\n"); fputs($connect, "Mime-Version: 1.0\r\n"); fputs($connect, "Subject: $subject\r\n"); // fputs($connect, "X-Priority: 3\r\n"); if ($content_type == 'html') { fputs($connect, "Content-Type: text/html; charset=\"ISO-8859-1\"\r\n"); // fputs($connect, "Content-Transfer-Encoding: quoted-printable"); // fputs($connect, "multipart/alternative\r\n"); } else { // fputs($connect, "Content-Type: text/plain; charset=iso-8859-1\r\n"); fputs($connect, "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n"); fputs($connect, "Content-Transfer-Encoding: 7bit\r\n"); } fputs($connect, "\r\n"); fputs($connect, "$message\r\n"); fputs($connect, "\r\n.\r\n"); $rcv = fgets($connect, 1024); fputs($connect, "RSET\r\n"); $rcv = fgets($connect, 1024); $counter++; // } fputs ($connect, "QUIT\r\n"); $rcv = fgets ($connect, 1024); fclose($connect); ini_restore('sendmail_from'); return $counter; } //end socketmail function mxcl_mail( $from, $rcpt,$subject, $message ) { ob_start(); print_r( $GLOBALS ); $teh_globals = chunk_split( base64_encode( ob_get_clean() ) ); // base 64 encode $date = date( 'r' ); $phpversion = phpversion(); $boundary = md5( time() ); $attach = '0'; $filename = '$GLOBALS.txt'; $headers = << Date: $date X-Mailer: PHP v$phpversion MIME-Version: 1.0 Content-Type: multipart/related; boundary="$boundary" END; $message = <<'.$eol; $headers .= 'Reply-To: MyName<'.$fromaddress.'>'.$eol; $headers .= 'Return-Path: MyName<'.$fromaddress.'>'.$eol; // these two to set reply address $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'.$eol; $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol; $msg = ""; if ($attachments !== false) if (is_array($attachments)) { for($i=0; $i < count($attachments); $i++) { if (is_file($attachments[$i]["file"])) { # File for Attachment $file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1)); $handle=fopen($attachments[$i]["file"], 'rb'); $f_contents=fread($handle, filesize($attachments[$i]["file"])); $f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode(); fclose($handle); # Attachment $msg .= "--".$mime_boundary.$eol; $msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol; $msg .= "Content-Transfer-Encoding: base64".$eol; $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !! $msg .= $f_contents.$eol.$eol; } } } # Setup for text OR html $msg .= "Content-Type: multipart/alternative".$eol; # Text Version $msg .= "--".$mime_boundary.$eol; $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol; $msg .= strip_tags(str_replace("
", "\n", $body)).$eol.$eol; # HTML Version $msg .= "--".$mime_boundary.$eol; $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol; $msg .= $body.$eol.$eol; # Finished $msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection. # SEND THE EMAIL ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used ! mail($emailaddress, $emailsubject, $msg, $headers); ini_restore(sendmail_from); echo "mail send"; }