Unknown PHP and Telnet error

1

I'm not able to send email using Telnet and PHP. The code connects to the server, however, from an unrecognized command.

$replyTo = '[email protected]';
$emailsTo = '[email protected]';
$headers = 'Email Teste';
$emailSubject = '[email protected]';
$body = 'Email de testes PHP e Telnet';

$telnet = array();
$telnet[0] = "telnet email.dominio.com.br 25\r\n";
$telnet[1] = "HELO www.dominio.com.br\r\n";
$telnet[2] = "mail from:$replyTo\r\n";
$telnet[3] = "RCPT TO:$emailsTo\r\n";
$telnet[4] = "data\r\n";
$telnet[5] = "From:$headers<$replyTo> \r\n To:$emailsTo\r\n Subject:$emailSubject\r\n        $body\r\n\r\n .\r\n";


$fp = fsockopen('email.dominio.com.br', 25);

$count = 0;
if (!$fp) {
    echo 'Falha de Conexão <hr>';
    return false;
} else {

    echo 'Conectado <hr>';

    foreach ($telnet as $current) {
        fwrite($fp, $current);
        $smtpOutput = fgets($fp);
        $g = substr($smtpOutput, 0, 3);

       var_dump($smtpOutput);

        if (!(($g == "220") || ($g == "250") || ($g == "354") || ($g == "500"))) {
            echo 'Falha de conexão 2';
        } else {
            $count = $count + 1;
            echo '   --    ' . $count . '<br>';
            if ($count > 5) {
                fclose($fp);
            }
        }
    }

}

Error Return:

Conectado

string(40) "220 email.newdrop.com.br ESMTP Postfix " -- 1
string(41) "502 5.5.2 Error: command not recognized " Falha de conexão 2string(26) "250 email.newdrop.com.br " -- 2
string(14) "250 2.1.0 Ok " -- 3
string(14) "250 2.1.5 Ok " -- 4
string(37) "354 End data with . " -- 5
    
asked by anonymous 11.05.2017 / 21:22

0 answers