-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path22-proxy-raw-smtps-protocol.php
45 lines (39 loc) · 1.5 KB
/
22-proxy-raw-smtps-protocol.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// A simple example which requests https://google.com/ through an HTTP CONNECT proxy.
// You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
//
// $ php leproxy.php
//
// The proxy defaults to 127.0.0.1:8080.
// To run the example, go to the project root and run:
//
// $ php examples/22-proxy-raw-smtps-protocol.php
//
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
//
// $ http_proxy=127.0.0.1:8080 php examples/22-proxy-raw-smtps-protocol.php
//
// This example highlights how changing from plain connections (see previous
// example) to using a secure connection actually adds very little complexity
// and does not mess with your actual network protocol otherwise.
// Please note that MANY public proxies do not allow SMTP connections, YMMV.
require __DIR__ . '/../vendor/autoload.php';
$url = getenv('http_proxy');
if ($url === false) {
$url = '127.0.0.1:8080';
}
$proxy = new Clue\React\HttpProxy\ProxyConnector($url);
$connector = new React\Socket\Connector(array(
'tcp' => $proxy,
'timeout' => 3.0,
'dns' => false
));
$connector->connect('tls://smtp.googlemail.com:465')->then(function (React\Socket\ConnectionInterface $connection) {
$connection->write("EHLO local\r\n");
$connection->on('data', function ($chunk) use ($connection) {
echo $chunk;
$connection->write("QUIT\r\n");
});
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});