diff -r 700d61d93b1b -r a044870a9d3d packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/smtp.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/smtp.php Fri Jan 11 00:32:54 2013 -0500 @@ -0,0 +1,111 @@ +\r\n"); + if ( _smtp_get_response($sock) !== 250 ) + throw new Exception("Expected 250"); + + // to + fputs($sock, "RCPT TO: <$to>\r\n"); + if ( _smtp_get_response($sock) !== 250 ) + throw new Exception("Expected 250"); + + // data + fputs($sock, "DATA\r\n"); + if ( !in_array(_smtp_get_response($sock), array(354, 250)) ) + throw new Exception("Expected 250 or 354"); + + // send headers + $full_headers = "Subject: $subject\r\n"; + $full_headers .= "From: <$from>\r\n"; + if ( !strstr($headers, "To: ") ) + $full_headers .= "To: <$to>\r\n"; + if ( !empty($headers) ) + $full_headers .= trim(str_replace("\n", "\r\n", str_replace("\r\n", "\n", $headers))) . "\r\n"; + + $full_headers .= "\r\n"; + fputs($sock, $full_headers); + + // send body + $body = str_replace("\n", "\r\n", str_replace("\r\n", "\n", $body)); + fputs($sock, $body); + + // send end marker + fputs($sock, "\r\n.\r\n"); + if ( _smtp_get_response($sock) !== 250 ) + throw new Exception("Expected 250"); + + // end session + fputs($sock, "QUIT\r\n"); + if ( _smtp_get_response($sock) !== 221 ) + throw new Exception("Expected 221"); + + fclose($sock); + } catch ( Exception $e ) + { + fputs($sock, "QUIT\r\n"); + _smtp_get_response($sock); + fclose($sock); + return false; + } + return true; +} + +function _smtp_get_response($sock) +{ + while ( !feof($sock) && ($line = fgets($sock, 8192)) ) + { + if ( preg_match('/^([0-9]+)(\s.+)?$/', $line, $match) ) + { + return intval($match[1]); + } + } + return false; +} + +// smtp_mail('plates@csh.rit.edu', 'plates@csh.rit.edu', 'Test e-mail', 'Testing', 'From: Plates '); +