18. august 2006 - 20:23Der er
5 kommentarer og 1 løsning
authentication til mail()
Warning: mail(): SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\Inetpub\vhosts\kpw.com.my\httpdocs\index.php on line 31
Hvad hulen goer man ved det? Serveren skal have authentication...
josephcmiller2 at gmail dot com 26-May-2006 04:26 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";
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";
// 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";
Ja, undskyld jeg forsøger at hjælpe dig, bare rolig det skal ikke ske igen.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.