Php 使用CURL通过代理发送电子邮件
我想用PHP编写一个脚本,通过代理连接smtp服务器上的TELNET。 到目前为止,我掌握的是这两种变体: 1 FSOCKOPEN(我无法代理此连接) 但它正在输出我:Php 使用CURL通过代理发送电子邮件,php,email,curl,smtp,fsockopen,Php,Email,Curl,Smtp,Fsockopen,我想用PHP编写一个脚本,通过代理连接smtp服务器上的TELNET。 到目前为止,我掌握的是这两种变体: 1 FSOCKOPEN(我无法代理此连接) 但它正在输出我: 220 omta01.emeryville.ca.mail.comcast.net comcast ESMTP server ready 250 omta01.emeryville.ca.mail.comcast.net hello [xx.xx.xx.xx], pleased to meet you 334 VXNlcm5hb
220 omta01.emeryville.ca.mail.comcast.net comcast ESMTP server ready
250 omta01.emeryville.ca.mail.comcast.net hello [xx.xx.xx.xx], pleased to meet you
334 VXNlcm5hbWU6
巫婆很好
还有另一种变体
2卷曲类
class ProxySmtp
{
private $server;
private $port;
private $proxy;
private $timeout;
private $curl_connection;
public function __construct($server,$port,$timeout = 10,$proxy = NULL)
{
echo "SERVER: $server:$port \n";
echo "PROXY: $proxy \n";
echo "TIMEOUT: $timeout \n";
// Set the config
$this->server = $server;
$this->port = $port;
$this->timeout = $timeout;
$this->proxy = $proxy;
// Start the curl
$this->curl_connection = curl_init($this->server.":".$this->port);
var_dump($this->curl_connection);
}
// Setters
public function setServer($newserver)
{
$this->server = $newserver;
}
public function setPort($newport)
{
$this->port = $newport;
}
public function setProxy($newproxy)
{
$this->proxy = $newproxy;
}
public function setTimeout($newtimeout)
{
$this->timeout = $newtimeout;
}
// Getters
public function getServer()
{
echo $this->server;
return $this->server;
}
public function curl_telnet($query)
{
if (!function_exists('curl_init'))
{
user_error('"curl_init()" function does not exist.', E_USER_WARNING);
return false;
}
curl_setopt($this->curl_connection, CURLOPT_TIMEOUT,$this->timeout);
curl_setopt($this->curl_connection, CURLOPT_CONNECTTIMEOUT,$this->timeout);
curl_setopt($this->curl_connection, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->curl_connection, CURLOPT_CUSTOMREQUEST,$query);
if($this->proxy != NULL)
{
echo "USING PROXY : ".$this->proxy."\n";
curl_setopt($this->curl_connection,CURLOPT_PROXY,$this->proxy);
curl_setopt($this->curl_connection,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
}
$output=curl_exec($this->curl_connection);
//curl_close($this->curl_connection);
if($output == false)
{
echo "CONNECTION ERROR!\n";
}
return $output;
}
public function __destruct()
{
$Destroy = curl_close($this->curl_connection);
echo "Object destroyed (".$Destroy.")! \n";
}
}
// Server,port,timeout,proxy(optional)
$ProxyAndPort = $Proxy.":".$ProxyPort;
$Smtp = new ProxySmtp($Server,$Port,$Timeout,$ProxyAndPort);
var_dump($Smtp->getServer());
var_dump($Smtp->curl_telnet("EHLO $User \r\n"));
var_dump($Smtp->curl_telnet("AUTH LOGIN \r\n"));
var_dump($Smtp->curl_telnet(base64_encode($user)." \r\n"));
var_dump($Smtp->curl_telnet(base64_encode($pass)." \r\n"));
var_dump($Smtp->curl_telnet("QUIT \r\n"));
巫婆给了我
string(389) "220 omta12.westchester.pa.mail.comcast.net comcast ESMTP server ready
250-omta12.westchester.pa.mail.comcast.net hello [85.204.11.249], pleased to meet you
250-HELP
250-AUTH LOGIN PLAIN
250-SIZE 36700160
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-STARTTLS
250 OK
500 5.5.1 command unrecognized
500 5.5.1 command unrecognized
450 4.7.0 too many invalid commands (closing session)
....
....
我有6个问题非常困扰我:
1为什么它只需一个简单的EHLO
命令就可以给我500 5.5.1
和450 4.7.0
?这是不可能的
<P>2为什么第一个例子与代码> FSOCKOPEN/<代码>一起工作,但我认为“卷曲女巫”更强大,具有代理功能,加上对象和类?
3为什么这个ProxyStp类可以在任何其他服务器上正常工作
4为什么我可以在cmd.exe(原始样式)中复制上面的所有命令并发送电子邮件
5使用“\r\n”对telnet说“执行线路”是否正确
6是否可以“代理”第一个脚本?(通过代理将fsock打开)
提示
据我所知,您不能以如下方式向COMCAST发送命令:
$command = "HELO smtp.comcast.net\r\n";
$command .= "AUTH LOGIN\r\n";
$command .= base64_encode("username")."\r\n";
$command .= base64_encode("password")."\r\n";
$command .= "QUIT\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}
你必须这样做(行,发送,行,发送…)
看来CURL不想这么做
我真的不可能理解这是怎么回事,需要使用PHP类,因为我应该使用类来构建我的WebMail服务器管理员,这是第一部分,我还必须研究IMAP和POP3协议
$command = "HELO smtp.comcast.net\r\n";
$command .= "AUTH LOGIN\r\n";
$command .= base64_encode("username")."\r\n";
$command .= base64_encode("password")."\r\n";
$command .= "QUIT\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}
$command = "HELO smtp.comcast.net\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}
$command = "AUTH LOGIN\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}
$command = base64_encode("username")."\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}
$command = base64_encode("password")."\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}
$command = "QUIT\r\n";
fwrite($connection,$command);
while (!feof($connection))
{
echo fgets($connection, 128)."\n";
}