2

我想通过 telnet 发送一封带有 PHP 的电子邮件,但这里出了点问题。

$telnet = array();
$telnet[0] = "telnet 10.0.50.6 25\r\n";
$telnet[1] = "HELO osiris.com\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('10.0.50.6', 25);

$count=0;

if (!$fp){
echo 'connection fail';

return false;   
}else{


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


        if (!(($g == "220") || ($g == "250") || ($g == "354")|| ($g == "500"))) {
        echo 'connection 2 fail';
             return false; 
    }else{
        $count=$count+1;
        echo $count.'<br>';
        if ($count>5){
            fclose($fp);
            return true;
        }
    }

结果是:

telnet 10.0.50.6 25 
220 afcc-ex-il1.rsa-otms.com Microsoft ESMTP MAIL Service ready at Sat, 30 Mar 2013 19:01:12 +0000 
220
1
HELO osiris.com 
500 5.3.3 Unrecognized command 
500
2
MAIL FROM:afcc@rsa.com 
250 afcc-ex-il1.rsa-otms.com Hello [10.0.70.22] 
250
3
RCPT TO:cfir@carmeli.me 
250 2.1.0 Sender OK 
250
4
DATA 
250 2.1.5 Recipient OK 
250
5
From:cfir To:cfir@carmeli.me Subject:test test
354 Start mail input; end with . 
354
6
4

1 回答 1

-1

您已完成所有操作,但在 \r\n 的下一行中只有一个额外的空格。\r\n

$telnet[5] = "From:$headers<$replyTo> \r\n To:$emailsTo\r\n Subject:$emailSubject\r\n        $body\r\n\r\n .\r\n"; 
于 2013-12-05T13:55:42.743 回答