注册一个邮箱,然后用下面的类 <? class smtp_sender { var $host; var $port; var $user; var $pass; var $debug = false; var $conn; var $result_str; var $in; var $from; var $to; var $subject; var $body; var $socket;
function smtp_sender($debug=false) { $this->smtp_ori('smtp.sina.com.cn','25','账号','密码',$debug);
<?
class smtp_sender
{
var $host;
var $port;
var $user;
var $pass;
var $debug = false;
var $conn;
var $result_str;
var $in;
var $from;
var $to;
var $subject;
var $body;
var $socket;
function smtp_sender($debug=false)
{
$this->smtp_ori('smtp.sina.com.cn','25','账号','密码',$debug);
}
function smtp_ori($host,$port,$user,$pass,$debug=false)
{
$this->host = $host;
$this->port = $port;
$this->user = base64_encode($user);
$this->pass = base64_encode($pass);
$this->debug = $debug;
$this->socket = fsockopen($this->host,$this->port, $errno, $errstr, 30);
if (!$this->socket)
{
die("error:$errstr ($errno)<br />\n");
}
}
function debug_show($str)
{
if($this->debug==true)
{
echo $str."<br>\r\n";
}
}
function send($from,$to,$subject,$body,$mailtype="html",$fromname="Hostelcn.com")
{
if($from == "" || $to == "")
{
exit("you must enter email address");
} if($subject == "") $sebject = "no subject";
if($body == "") $body = "no content";
$body = str_replace("\n", "\r\n", $body);
$body = str_replace("\r\r", "\r", $body);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body; $All = "From: $fromname<".$this->from.">\r\n";
$All .= "To: ".$this->to."\r\n";
$All .= "Subject: ".$this->subject."\r\n";
$All .= "MIME-Version: 1.0\r\n";
if(strtolower($mailtype)=="html")
$All .="Content-Type: text/html;charset=\"gb2312\"\r\n";
$All .= "Date: ".date("r")."\r\n";
$All .= "X-Mailer: Microsoft Outlook Express 5.50.4522.1200\r\n";
list($msec, $sec) = explode(" ", microtime());
$All .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$from.">\r\n\r\n";
$All .= $this->body;
$this->in = "EHLO HELO\r\n";
$this->sendcommand();
$this->in = "AUTH LOGIN\r\n";
$this->sendcommand();
$this->in = $this->user."\r\n";
$this->sendcommand();
$this->in = $this->pass."\r\n";
$this->sendcommand();
$this->in = "MAIL FROM:".$this->from."\r\n";
$this->sendcommand();
$this->in = "RCPT TO:".$this->to."\r\n";
$this->sendcommand();
$this->in = "DATA\r\n";
$this->sendcommand();
$this->in = $All."\r\n.\r\n";;
$this->sendcommand();
$this->in = "QUIT\r\n";
$this->sendcommand();
}
function sendcommand()
{
fwrite($this->socket, $this->in);
$this->debug_show("Command:".$this->in);
$this->result_str = "Response".fread ($this->socket, 1024)."";
$this->debug_show($this->result_str);
}
} ?>
header("Content-Type:text/html;charset=GB2312");
function TOJMail($From,$FromName,$FromUser,$FromPass,$TOMail,$TOTitle,$TOContent,$SmtpServer)
{
$jmail=new COM("JMail.Message")or die("无法调用Jmail组件");
$jmail->logging="true";
$jmail->From=$From;
$jmail->FromName=$FromName;
$jmail->AddRecipient($TOMail);
$jmail->Subject=$TOTitle;
$jmail->Body=$TOContent;
$jmail->MailServerUserName=$FromUser;
$jmail->MailServerPassword=$FromPass;
$jmail->Send($SmtpServer);
echo "发送成功";
}$From = "[email protected]"; //发件人地址
$FromName = "靖康科技"; //发件人姓名
$FromUser = "[email protected]"; //发件人用户名
$FromPass = "web"; //发件人密码
$TOMail = "[email protected]"; //收件人地址
$TOTitle = " PHP+Jmail测试发送邮件"; //邮件标题
$TOContent = " PHP+Jmail测试发送邮件"; //邮件内容
$SmtpServer = "mail.99419.com"; //邮件服务器
TOJMail($From,$FromName,$FromUser,$FromPass,$TOMail,$TOTitle,$TOContent,$SmtpServer);
?>