I am trying to check mail using telnet and php. The whole words of the process are fine in the terminal, but when I use php shell_exec(), it starts only before the Telnet connection command. After connecting telnet, the remaining telnet commands no longer work.
Is there any other way that we need to execute telnet using php?
The UPDATE . I am trying to replicate this tutorial.
Here is my code
public function mailtest(Request $request){
$email = $request->input("email");
$divide = explode("@", $email);
$server = $divide[1];
$response = shell_exec("nslookup -q=mx $server");
print_r($response);
$mailServerList = explode(PHP_EOL, $response);
$line = $mailServerList[4];
$serverArr = preg_split('/\s+/', $line);
$n = sizeof($serverArr);
$mailServer = $serverArr[$n-1];
print_r($mailServer);
$telnet = shell_exec("telnet $mailServer 25");
print_r("telnet response ".$telnet);
$helo = shell_exec("Helo testing.com");
print_r("Helo response ".$helo);
$from = shell_exec('mail from: testing@gmail.com');
print_r("MAil from response ".$from);
$finalResponse = shell_exec("rcpt to: $email");
print_r("Mail to response ".$finalResponse);
}
And here is the answer
Server: 10.0.80.11
Address: 10.0.80.11#53
Non-authoritative answer:
gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
Authoritative answers can be found from:
gmail-smtp-in.l.google.com internet address = 173.194.64.27
gmail-smtp-in.l.google.com has AAAA address 2607:f8b0:4003:c02::1a
alt1.gmail-smtp-in.l.google.com internet address = 173.194.219.27
alt1.gmail-smtp-in.l.google.com has AAAA address 2607:f8b0:4002:c03::1b
alt4.gmail-smtp-in.l.google.com internet address = 64.233.190.26
alt4.gmail-smtp-in.l.google.com has AAAA address 2800:3f0:4003:c01::1b
alt3.gmail-smtp-in.l.google.com internet address = 74.125.141.26
alt3.gmail-smtp-in.l.google.com has AAAA address 2607:f8b0:400c:c06::1a
alt2.gmail-smtp-in.l.google.com internet address = 173.194.205.27
alt2.gmail-smtp-in.l.google.com has AAAA address 2607:f8b0:400d:c02::1b
gmail-smtp-in.l.google.com.telnet response Trying 2607:f8b0:4003:c02::1a...
Connected to gmail-smtp-in.l.google.com.
Escape character is '^]'.
Helo response
MAil from response No message, no subject; hope that ok
Mail to response
source
share