For everyone to give a PHP use SMTP to send mail code, simple and practical, the need for friends, you can refer to the next. The complete code is as follows.
' Scripting School ',//fill in the name of the website here); $mail = Array (' state ' = = 1, ' server ' = ' smtp.abc.com ', ' port ' = ', ' auth ' = 1, ' Us Ername ' + ' admin@abc.com ', ' Password ' and ' 123456 ', ' charset ' = ' gbk ', ' mailfrom ' and ' admin@abc.com '); functi On SendMail ($mail _to, $mail _subject, $mail _message) {global $mail, $bfconfig; Date_default_timezone_set (' PRC '); $mail _ Subject = ' =? '. $mail [' CharSet ']. B? '. Base64_encode ($mail _subject). '? ='; $mail _message = Chunk_split (Base64_encode (Preg_replace ("/"/(^| ( \ n)) (\.) /"," \1.\3 ", $mail _message))); $headers. = ""; $headers. = "mime-version:1.0\r\n"; $headers. = "content-type:text/html\r\n"; $headers. = "content-transfer-encoding:base64\r\n"; $headers. = "From:". $bfconfig [' SiteName ']. " < ". $mail [' Mailfrom ']." >\r\n "; $headers. = "Date:". Date ("R"). " \ r \ n "; List ($msec, $sec) = Explode ("", Microtime ()); $headers. = "Message-id: <". Date ("Ymdhis", $sec). ".". ($MSEC * 1000000). ".". $mail [' Mailfrom ']. " >\r\n "; if (! $fp = Fsockopen ($mail [' Server '], $mail[' Port '], $errno, $errstr,) {exit ("connect-unable to CONNECT to the SMTP server"), Stream_set_blocking ($FP, Tru e); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! = ' + ') {exit ("CONNECT-". $lastmessage);} Fputs ($FP, ($mail [' auth ']? ' EHLO ': ' HELO '). "befen\r\n"); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! = && substr ($lastmessage, 0, 3)! =) {exit ("Helo/ehlo-". $lastmessage); } while (1) {if (substr ($lastmessage, 3, 1)! = '-' | | | empty ($lastmessage)) {break; } $lastmessage = Fgets ($FP, 512); } if ($mail [' auth ']) {fputs ($fp, "auth login\r\n"); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! = 334) {exit ($lastmessage); } fputs ($FP, Base64_encode ($mail [' username ']). " \ r \ n "); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! = 334) {exit ("AUTH LOGIN-". $lastmessage); } fputs ($FP, Base64_encode ($mail [' Password ']). " \ r \ n "); $lastmessage = fgets ($FP, 512); if (substr ($lastmeSsage, 0, 3)! = 235) {exit ("AUTH LOGIN-". $lastmessage); } $email _from = $mail [' Mailfrom ']; } fputs ($FP, "MAIL from: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $email _from)." >\r\n "); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! =) {fputs ($fp, "MAIL from: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $email _from)." >\r\n "); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! =) {exit ("MAIL from-". $lastmessage); }} foreach (Explode (', ', $mail _to) as $touser) {$touser = Trim ($touser); if ($touser) {fputs ($fp, "RCPT to: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $touser)." >\r\n "); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! =) {fputs ($fp, "RCPT to: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $touser)." >\r\n "); $lastmessage = fgets ($FP, 512); Exit ("RCPT to-". $lastmessage); }}} fputs ($fp, "data\r\n"); $lastmessage = fgets ($FP, 512); if (substr ($lastmessaGE, 0, 3)! = 354) {exit ("DATA-". $lastmessage);} Fputs ($fp, $headers); Fputs ($FP, "to:". $mail _to. " \ r \ n "); Fputs ($FP, "Subject: $mail _subject\r\n"); Fputs ($fp, "\r\n\r\n"); Fputs ($fp, "$mail _message\r\n.\r\n"); $lastmessage = fgets ($FP, 512); if (substr ($lastmessage, 0, 3)! =) {exit ("END-". $lastmessage);} Fputs ($fp, "quit\r\n");}? > |