note 66705 added to ref.mail

From: Date: Fri, 26 May 2006 14:26:27 +0000
Subject: note 66705 added to ref.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-112334@lists.php.net to get a copy of this message
I have been using the function mymail() provided by Antony Male (below) to send mail on my server, but with a couple of modifications. First, I needed to enable AUTH LOGIN in order to use my smtp server from my ISP. Second, his mymail() function allows for a $from to be used, but the function does not accept any such parameter. I have addressed the latter issue by parsing the headers to obtain the From: address. If this is not provided, failed mail will not be returned properly to the sender. // modified to provide authenticated logins function mymail($to,$subject,$message,$headers) { // set as global variable global $GLOBAL; // get From address if ( preg_match("/From:.*?[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.*/", $headers, $froms) ) { preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+/", $froms[0], $fromarr); $from = $fromarr[0]; } // Open an SMTP connection $cp = fsockopen ($GLOBAL["SMTP_SERVER"], $GLOBAL["SMTP_PORT"], &$errno, &$errstr, 1); if (!$cp) return "Failed to even make a connection"; $res=fgets($cp,256); if(substr($res,0,3) != "220") return "Failed to connect"; // Say hello... fputs($cp, "HELO ".$GLOBAL["SMTP_SERVER"]."\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "250") return "Failed to Introduce"; // perform authentication fputs($cp, "auth login\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "334") return "Failed to Initiate Authentication"; fputs($cp, base64_encode($GLOBAL["SMTP_USERNAME"])."\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "334") return "Failed to Provide Username for Authentication"; fputs($cp, base64_encode($GLOBAL["SMTP_PASSWORD"])."\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "235") return "Failed to Authenticate"; // Mail from... fputs($cp, "MAIL FROM: <$from>\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "250") return "MAIL FROM failed"; // Rcpt to... fputs($cp, "RCPT TO: <$to>\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "250") return "RCPT TO failed"; // Data... fputs($cp, "DATA\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "354") return "DATA failed"; // Send To:, From:, Subject:, other headers, blank line, message, and finish // with a period on its own line (for end of message) fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "250") return "Message Body Failed"; // ...And time to quit... fputs($cp,"QUIT\r\n"); $res=fgets($cp,256); if(substr($res,0,3) != "221") return "QUIT failed"; return true; } ---- Server IP: 64.71.164.2 Probable Submitter: 71.48.24.78 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.mail.php Edit -- http://master.php.net/note/edit/66705 Del: integrated -- http://master.php.net/note/delete/66705/integrated Del: useless -- http://master.php.net/note/delete/66705/useless Del: bad code -- http://master.php.net/note/delete/66705/bad+code Del: spam -- http://master.php.net/note/delete/66705/spam Del: non-english -- http://master.php.net/note/delete/66705/non-english Del: in docs -- http://master.php.net/note/delete/66705/in+docs Del: other reasons-- http://master.php.net/note/delete/66705 Reject -- http://master.php.net/note/reject/66705 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112334) next »