Avatar billede flemche Nybegynder
06. oktober 2013 - 14:11 Der er 2 kommentarer og
1 løsning

SMTP Script: 500 unrecognized command

Hejsa

For 1½ år siden fandt jeg et PHP script, hvor jeg kunne sende mails via min internet udbyders SMTP server (STOFA), istedet for at sætte min egen op.

Det har virket upåklageligt, men jeg er begyndt at få nogle fejl i scriptet og mails bliver ikke længere afsendt.

Som jeg ser der kommer der 2 "500 unrecognized command" som nok er det der er fejlen.

Jeg har forsøgt at finde et svar på nettet men uden held.
Måske er der nogen herinde som kan give en forklaring.

------------ response fra SMTP server -----------
connection accepted
220 mx06.stofanet.dk - StofaNet Mail Server.

Continuing

3....250 mx06.stofanet.dk Hello 563453ef.rev.stofanet.dk [86.52.83.239]
4....503 AUTH command used when not advertised
5....500 unrecognized command
6....500 unrecognized command
7....250 OK
8....250 Accepted
9....354 Enter message, ending with "." on a line by itself
11....250 OK id=1VSmSN-0006Hs-2L
12....221 mx06.stofanet.dk closing connection

Hi Flemming, Bla Bla Bla......




------------ PHP Script -----------

function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
    {
      // 1.0 Initializing variables
      $smtpServer = "mail.stofanet.dk";    // IP address of the mail server.  This can also be the local domain name
      $port = "25";                            // Should be 25 by default, but needs to be whichever port the mail server will be using for smtp
      $timeout = "45";                        // Typical timeout. try 45 for slow servers
      $username = "********";            // The login for your smtp
      $password = "********";                // The password for your smtp
      $localhost = "127.0.0.1";                // Defined for the web server.  Since this is where we are gathering the details for the email
      $newLine = "\r\n";                    // Aka, carrage return line feed. var just for newlines in MS
      $secure = 0;                            // Change to 1 if your server is running under SSL

      // 2.0 Connect to the host and port
      $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
      $smtpResponse = fgets($smtpConnect, 4096);
      if(empty($smtpConnect))
        {
          $output = "Failed to connect: $smtpResponse";
          echo $output;
          return $output;
        }
      else
        {
          $logArray['connection'] = "<p>Connected to: $smtpResponse";
          echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
        }

      // 3.0 You have to say HELO again after TLS is started
      fputs($smtpConnect, "HELO $localhost". $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['heloresponse2'] = "$smtpResponse";
      echo ("3....");
      echo ($smtpResponse);
      echo "<br/>";

      // 4.0 Request for auth login
      fputs($smtpConnect,"AUTH LOGIN" . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['authrequest'] = "$smtpResponse";
      echo ("4....");
      echo ($smtpResponse);
      echo "<br/>";

      // 5.0 Send the username
      fputs($smtpConnect, base64_encode($username) . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['authusername'] = "$smtpResponse";
      echo ("5....");
      echo ($smtpResponse);
      echo "<br/>";

      // 6.0 Send the password
      fputs($smtpConnect, base64_encode($password) . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['authpassword'] = "$smtpResponse";
      echo ("6....");
      echo ($smtpResponse);
      echo "<br/>";

      // 7.0 Define e-mail from
      fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['mailfromresponse'] = "$smtpResponse";
      echo ("7....");
      echo ($smtpResponse);
      echo "<br/>";

      // 8.0 Define e-mail to
      fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['mailtoresponse'] = "$smtpResponse";
      echo ("8....");
      echo ($smtpResponse);
      echo "<br/>";

      // 9.0 Construct e-mail
      fputs($smtpConnect, "DATA" . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['data1response'] = "$smtpResponse";
      echo ("9....");
      echo ($smtpResponse);
      echo "<br/>";

      // 10.0 Construct headers
      $headers = "MIME-Version: 1.0" . $newLine;
      $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
      $headers .= "To: $nameto <$to>" . $newLine;
      $headers .= "From: $namefrom <$from>" . $newLine;

      // 11.0 Send e-mail - observe the . after the newline, it signals the end of message
      fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['data2response'] = "$smtpResponse";
      echo ("11....");
      echo ($smtpResponse);
      echo "<br/>";

      // 12.0 Say goodbye
      fputs($smtpConnect,"QUIT" . $newLine);
      $smtpResponse = fgets($smtpConnect, 4096);
      $logArray['quitresponse'] = "$smtpResponse";
      $logArray['quitcode'] = substr($smtpResponse,0,3);
      fclose($smtpConnect);
      //a return value of 221 in $retVal["quitcode"] is a success
      echo ("12....");
      echo ($smtpResponse);
      return($logArray);

    } // End of function authgMail
Avatar billede anri Novice
07. oktober 2013 - 08:39 #1
Ja det ser jo ud til at de har skiftet server-software til noget der ikke genkender AUTH LOGIN

Den hurtige test: Jeg har læst et sted at nogle SMTP servere skal have kommandoen AUTH=LOGIN i stedet for.  Prøv lige det.

En måde kunne være at koble op via en mail-klient og så bruge en packet sniffer til at se hvad der bliver sendt frem og tilbage, og så benytte samme kommandoer i dit PHP script.
Avatar billede flemche Nybegynder
05. april 2014 - 09:38 #2
Det virkede ikke, men jeg fandt en anden vej ved at lave om i mon kode.

Skriv hvis du vil have point.

/Flemming
Avatar billede flemche Nybegynder
07. juni 2014 - 12:25 #3
Løsning fundet
Avatar billede Ny bruger Nybegynder

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.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester