소켓으로 메일보내기 | |||
| |||
$fromdomain = 'mydomain.co.kr'; $fromname = '관리자'; $to = 'yourid@hanmail.net'; $todomain = 'hanmail.net'; $toname = '아무개'; $subject = '테스트메일 입니다.'; $data = "To: $toname <$to> From: $fromname <$from> Subject: $subject Content-Type: text/html; charset=Korean Content-Transfer-Encoding: base64 ".base64_encode("testmail<br />testmail<br />testmail")." . "; $errno = 0; $errstr = 0; echo "Connect Start... "; if(false === getmxrr($todomain, $mxhosts)) exit("no mx record "); $nbsp; $rows = count($mxhosts); $fastmx = 0; $oldtime = 999; for($i = 0; $i < $rows; $i ++) { $starttime = explode(' ', microtime()); if(false === ($socks[$i] = fsockopen($mxhosts[$i], 25, $errno, $errstr, 30))) { echo $mxhosts[$i]." not connected "; continue; } else $sock_close[] = $i; $endtime = explode(' ', microtime()); $thistime[0] = $endtime[0] - $starttime[0]; $thistime[1] = $endtime[1] - $starttime[1]; $ttime = $thistime[0] + $thistime[1]; echo $mxhosts[$i]." $ttime "; if($ttime < $oldtime) { $oldtime = $ttime; $fastmx = $i; } } $sock = &$socks[$fastmx]; echo $mxhosts[$fastmx]." Connected errno:$errno errstr:$errstr "; $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "1 $response "; if(substr($response, 0, 3) != '220') exit("Connection failure "); fputs($sock, "EHLO $fromdomain "); $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "2 $response "; if(substr($response, 0, 3) != '250') exit("EHLO failure "); fputs($sock, "MAIL FROM: $from "); $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "3 $response "; if(substr($response, 0, 3) != '250') exit("MAIL FROM failure "); fputs($sock, "RCPT TO: $to "); $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "4 $response "; if(substr($response, 0, 3) != '250') exit("RCPT TO failure "); fputs($sock, "DATA "); $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "5 $response "; if(substr($response, 0, 3) != '354') exit("DATA failure "); fputs($sock, $data); $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "6 $response "; if(substr($response, 0, 3) != '250') exit("MESSAGES failure "); fputs($sock, "QUIT "); $response = fread($sock, 256); $bytes_left = socket_get_status($sock); if($bytes_left > 0) $response .= fread($sock, $bytes_left['unread_bytes']); echo "7 $response "; if(substr($response, 0, 3) != '221') exit("QUIT failure "); $rows = count($sock_close); for($i = 0; $i < $rows; $i ++) fclose($socks[$sock_close[$i]]); Tags: mail socket | |||
| |||
| |||
로그인을 하시면 댓글을 등록 할 수 있습니다. |
SIMILAR POSTS 폼메일 예제 |
OTHER POSTS IN THE SAME CATEGORY 매번 rand결과가 같게 나오지 않게 하려면 |