不使用smtp直接发送邮件
用smtp发邮件挺蛋疼的,不是有配额限制就是有配额限制.所以我觉得应该有直接发送邮件的办法.回归到用命令行装逼的年代,我们是这样发信的:
C:\>nslookup
默认服务器: google-public-dns-a.google.com
Address: 8.8.8.8
> set type=mx
> qq.com
服务器: google-public-dns-a.google.com
Address: 8.8.8.8
非权威应答:
qq.com MX preference = 10, mail exchanger = mx3.qq.com
qq.com MX preference = 20, mail exchanger = mx2.qq.com
qq.com MX preference = 30, mail exchanger = mx1.qq.com
C:\>telnet mx3.qq.com 25
220 newmx13.qq.com MX QQ Mail Server
HELO localhost
250 newmx13.qq.com
MAIL FROM:<eslizn@localhost>
250 Ok
RCPT TO:<10000@qq.com>
250 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
hello!
.
550 Mail content denied. //service.mail.qq.com/cgi-bin/help?subtype=1&&id=20022&&no=1000726
QUIT
虽然邮件没有发送成功,但是是因为被过滤了,最好做下spf以及写全邮件头信息.
显然,我们可以利用程序模拟这个过程:
function realmail($to,$subject,$message,$from,$type="text/plain"){
$rule="/([a-zA-Z0-9-.]+)\@([a-zA-Z0-9-.]+)/i";
if(!pregmatch($rule,$to,$to) || !pregmatch($rule,$from,$from)){
return false;
}
if (!getmxrr($to[2],$mx)){
return false;
}
$message = array(
"MIME-Version: 1.0",
"X-Mailer: Xmailer",
"Delivered-To: {$to[0]}",
"From: {$from[1]} <{$from[0]}>",
"To: {$to[1]} <{$to[0]}>",
"Date: ".date("D, t F Y H:i:s O"),
"Content-Type: {$type}; charset=UTF-8",
"Content-Transfer-Encoding: base64",
"Subject: =?UTF-8?B?".base64encode($subject)."?=",
"",
base64encode($message)
);
$cmds=array(
"HELO {$from[2]}",
"MAIL FROM:<{$from[0]}>",
"RCPT TO:<{$to[0]}>",
"DATA",
implode("\r\n",$message)."\r\n.\r\n",
"QUIT"
);
$fp=fsockopen(current($mx),25);
foreach($cmds as $val){
fwrite($fp,$val."\r\n");
fgets($fp);
}
fclose($fp);
return true;
}
这样就不用给smtp跪舔了,邮件想发就发