php搭建邮件服务器
㈠ 新手想做一个php的表单提交发送到指定邮箱,请高手指教
首先包含一个邮件发送类 require("sendMail.php");
然后你要有一个发送邮件的服务器(可以到163随意注册个,例如注册的是[email protected],密码是aa123),然后是发送邮件的代码,我给你一个我用的例子
$smtpserver = "smtp.163.com"; //你选择的SMTP服务器
$smtpserverport =25; //SMTP服务器端口
$smtpusermail = "[email protected]"; //SMTP服务器的用户邮箱
$smtpemailto = "[email protected]"; //收件箱
$smtpuser = "[email protected]"; //SMTP服务器的用户帐号
$smtppass = "aa123"; //SMTP服务器的用户密码
$MailBody="姓名:".$_POST['Name'];//邮件内容(如你提交的表单姓名为Name)
$mailsubject=@iconv("UTF-8", "gb2312", "XX网站-问题提交");//如果你页面为UTF-8,这里还要转码一下
$mailbody = $MailBody; //邮件内容
$mailtype = "HTML"; //邮件格式(HTML/TXT),TXT为文本邮件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//true表示使用身份验证,否则不使用身份验证.
$smtp->debug = FALSE; //是否显示发送的调试信息 TRUE发送 FALSE不发送
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
sendMail.php代码:
class smtp
{
/* Public Variables */
var $smtp_port; //邮件服务器端口
var $time_out; //超时时间
var $host_name; //主机名称
var $log_file; //日志文件
var $relay_host; //
var $debug;
var $auth;
var $user; //用户名
var $pass; //密码
var $sock;
/* Constractor */
function smtp($relay_host, $smtp_port,$auth,$user,$pass)
{
// echo $relay_host." ".$smtp_port." ".$auth." ".$user." ".$pass;
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30;//is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost";//is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug) {
//echo $message;
}
}
}
㈡ 请问一下,PHP配置SMTP怎么弄
PHPMailer的获取:
PHPMailer项目地址:PHPMailer 使用git命令克隆到本地,或直接在该项目页面的右下方点击“ Download ZIP ”即可获取到完整的PHPMailer代码包,再到本地解压即可。
步骤一:使我们的QQ邮箱能够发送邮件
这里怎么说能够发送邮件呢?其实我们的邮箱都是可以发送邮件的,但是要实现在我们的网站中发送邮件,那就要设置一下我们的QQ邮箱了,因为此时我们的网站现在是作为一个第三方客户端存在的。
步骤一:使我们的QQ邮箱能够发送邮件
这里怎么说能够发送邮件呢?其实我们的邮箱都是可以发送邮件的,但是要实现在我们的网站中发送邮件,那就要设置一下我们的QQ邮箱了,因为此时我们的网站现在是作为一个第三方客户端存在的
由于待会我们用到的是SMTP服务器来发送,在这里建议把前面的两项开启了!当你点击开启的时候,它会提示:
下载一个phpmailer类,里面主要的是三个文件class.phpmailer.phpclass.pop3.phpclass.smtp.php
将这三个文件放到同一个文件夹.eg:papmailer
申请一个网络邮件服务器(我用的是163服务器)
编写发送邮件代码如下
/**
*发送邮件
*@paramunknown_type$sendto_email接收人Email
*@paramunknown_type$subject邮件主题
*@paramunknown_type$body邮件内容
*@paramunknown_type$user_name接受人姓名
*/
functionsend_email($sendto_email,$subject,$body,$user_name){
require_once"phpmailer/class.phpmailer.php";
$mail=newPHPMailer();//创建类对象
$mail->IsSMTP();
$mail->Host="smtp.163.com";//SMTPservers使用163服务器,邮件smtp服务器
$mail->SMTPAuth=true;//turnonSMTPauthentication
$mail->Username="你申请的163邮箱帐号";//SMTPusername注意:普通邮件认证不需要加@域名
$mail->Password="163邮箱密码";//SMTPpassword
$mail->From="发件人邮箱,可以使用上面163邮箱";//发件人邮箱
$mail->FromName="发件人名称,自己随意命名";//发件人
$mail->CharSet="utf8";//这里指定字符集!
$mail->Encoding="base64";
$mail->AddAddress($sendto_email,$user_name);//收件人邮箱和姓名
$mail->IsHTML(true);//sendasHTML
//邮件主题
$mail->Subject=$subject;
//邮件内容
$mail->Body=$body;
$mail->AltBody="text/html";
if(!$mail->Send()){
return$mail->ErrorInfo;
}else{
returntrue;
}
}
<?phprequire_once("./functions.php");$flag=sendMail('[email protected]','lsgo在线通知','恭喜你成功加入LSGO实验室,开启你的学习之旅吧!');if($flag){echo"发送邮件成功!";
}else{echo"发送邮件失败!";
}?>
㈢ php怎么通过第三方邮件服务器来发送邮件
用 PHPMailer ,这是一个邮件发送插件,到网上下载一个,具体的使用官网有方法的,很简单。
swiftMailer 也可以的。
php自带的mailer方法需要系统的支持,如果是linux的话可以直接使用,而windows就麻烦了,就用上面说的两个插件中的任何一个就行了,
㈣ Postfix邮件服务器和PHP配合
不知道您为什么要自己搭建邮件服务器+web邮箱系统。对新手而言,是一件挺有挑战性的事情。
邮件服务器一般我们会考虑网络上很多免费的,它们一般技术成熟,服务器稳定,而且都是免费的。您架设的,质量上不一定比它们更好。
而web邮箱管理系统,目前也有很多。对今天的用户而言,也没有太多吸引力,因为有很多的替代品。微软的outlook,国产的foxmail都有多年的历史,也很优秀。而现在移动互联网时代,手机App也很有优势。
我猜测,您是不是想让会员在站内发短信?这跟邮件是两码事。
或者,您只是想通过php系统,给会员的邮箱发邮件?这用不着您架设邮件服务器。
当然,您可能爱上了Postfix,因为偶尔得到一个别致的领带胸针,最后为它配了一整套的西装革履也有可能。
好吧,我来回答您的问题。
1、如何对Postfix收到邮件进行管理?
您需要编写基本的两个程序,收和发。收和发的代码,比比皆是,代码并不复杂。但是您要弄清楚架构。
您的邮件服务器和邮件用户代理服务器(会员系统)在同一个主机上,但您得想成是两个服务,两个系统。就是说,您收邮件时候,读取到邮件后,将数据存到会员系统的mysql上。这个邮件在这台服务器上实际上有两份了。一般服务器软件不会用到mysql,邮件以其他形式在硬盘上存储。
发邮件,您可以通过您Postfix提供的smtp服务往外发。数据您自己通过php程序保留一份,在您会员系统的mysql里。Postfix没必要保留发出去的邮件。
2.mysql在这里面的角色是不是只管理用户的帐号密码信息?
如上所述,mysql当然要保留用户的帐号密码信息。但不仅如此,要保留发件的内容,还要放收到的邮件内容。
3.对于新手来说怎样做最容易达到预期效果。
万能的网络,一切用现成的就好。
您找到了Postfix,这是邮件服务器。这个架设也不难,网上教程比比皆是。
如果只想做邮件,不想其他的,您搜一个免费的Webmail在线邮件系统就好了。英文的较多,自己做一下汉化。PostfixAdmin可以研究下,它可以和Postfix实现mysql数据共享。
中文的,extmail比较有名,它是一个套件,什么都有,包括Postfix,拿来研究下直接用,无需二次开发。
㈤ 用PHP做一个邮件系统 不知道怎么下手
你要做的话,其实就是邮件的保存了,当然附件是保存在服务器上,这个上传就是了。
内容的话,看你是保存数据库还是保存文本了,其实两者都是数据源。如果要稳定或者是以后开发的 方便的话,选择数据库吧。
另外SMTP是邮件的接收协议,POP3是邮件的发送协议,一般来说,我们是用的POP3和STMP组合,这个是需要单独的配置服务器的。PHP只是通过MAIL来链接这两个服务器进行邮件的发送和接收工作。
㈥ php调用jmail组建发邮件,代码贴不出来,
<?
class Jmail
{
public $Username; //邮局用户名
public $Password; //密码
public $FormName ; //发件人姓名
public $From ; //发件人地址
public $Addrecipient ; //收件人地址
public $Ttile ; //邮件标题
public $Content; //邮件内容
public $Smtp; //邮件服务器
function Send(){
$Jmail = new com("Jmail.Message"); //实例化一个Jmail对象
$Jmail->SiLent=true; //设置成True的话Jmail不会提示错误只会返回True和False
$Jmail->LogGing = false; //是否开启日志
$Jmail->CharSet = "GB2312"; //设定字符串编码
$Jmail->ContentType = "Text/html"; //邮件的格式为HTML格式
$Jmail->MailServerUsername = $this->Username; //发信箱用户名
$Jmail->MailServerPassword = $this->Password; //发信箱密码
$Jmail->FromName = $this->FromName; //发件人姓名
$Jmail->From = $this->From; //发件人地址
$Jmail->AddRecipient($this->Addrecipient); //收件人地址
$Jmail->Subject = $this->Title;//Email标题
$Jmail->Body = $this->Content; //Email正文
$JmailError = $Jmail->Send($this->Smtp); //Smtp服务器
if($JmailError){ //判断邮件是否发送成功
return true;
}else{
return false;
}
}
}
//这里是调用代码
$jmail = new Jmail();
$jmail->Username = "lwf0757";
$jmail->Password = "0757";
$jmail->FromName = "梁";
$jmail->From = "[email protected]";
$jmail->Addrecipient = "[email protected]";
$jmail->Title = "这是标题";
$jmail->Content = "这是内容";
$jmail->Smtp = "smtp.163.com";
if($jmail->Send()){
echo "成功哦!";
}else{
echo "失败哦!";
}
?>
㈦ 使用Foxmail如何搭建本地SMTP服务器,用于测试PHP发送邮件功能。
foxmail是客户端软件,直接用server 2003的pop3服务就可以搭建smtp服务器了。
㈧ 用hmailserver+PHP+mysql建了一个邮件系统。60多帐号,全用OE客户端.有部分可以收,有部分收不到
自己的邮件服务器很难保证邮件的到达率,建议使用第三方邮件服务提供商(ESP)
Amazon SES (http://aws.amazon.com/ses/)
PostMark (http://www.postmarkapp.com/)
CritSend (http://www.critsend.com/)
SendGrid (http://sendgrid.com/)
SocketLabs (http://www.socketlabs.com/)
MailChimp (http://www.mailchimp.com/)
㈨ php发送邮件的问题:php怎么才能发送邮件呢使用自带的函数,应该怎样设置相应的邮件服务器
首先,我不想给phpmailer这个东西做广告,但是我确实使用的这个东西,很费解。
㈩ php怎么实现发送邮件
PHP发送邮件是“非常的简单” 因为他提供了mail()函数直接发送,但配置相当麻烦 (1)通过mail()函数发送邮件 mail() 配置PHP.ini 邮件信息 需要类似sendmail这样的组件支持 (2)通过socket通讯,使用SMTP传输 socket连接->SMTP通讯->获取通讯消息->发送 mail函数的使用 mail() 函数允许您从脚本中直接发送电子邮件。 如果邮件的投递被成功地接收,则返回 true,否则返回 mail(to,subject,message,headers,parameters) socket方式发送原理 给你一个别人写好的类 用法在下面 本人经测试很多网站都不提供免费的smtp服务(126、sina、netease 这几个试过了),腾讯邮箱支持此功能。 用法: <? require_once ('email.class.php'); //########################################## $smtpserver = "smtp.163.com";//SMTP服务器 $smtpserverport =25;//SMTP服务器端口 $smtpusermail = "";//SMTP服务器的用户邮箱 $smtpemailto = "";//发送给谁 $smtpuser = "";//SMTP服务器的用户帐号 $smtppass = "";//SMTP服务器的用户密码 $mailsubject = "PHP100测试邮件系统";//邮件主题 $mailbody = "<h1> 这是一个测试程序 PHP100.com </h1>";//邮件内容 $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件 ########################################## $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证. $smtp->debug = FALSE;//是否显示发送的调试信息 $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); ?> 邮件发送类 <? class smtp { /* Public Variables */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; /* Private Variables */ var $sock; /* Constractor */ function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass) { $this->debug = FALSE; $this->smtp_port = $smtp_port; $this->relay_host = $relay_host; $this->time_out = 30; //is used in fsockopen() # $this->auth = $auth;//auth $this->user = $user; $this->pass = $pass; # $this->host_name = "localhost"; //is used in HELO command $this->log_file =""; $this->sock = FALSE; } /* Main Function */ function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "") { $mail_from = $this->get_address($this->strip_comment($from)); $body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body); $header .= "MIME-Version:1.0\r\n"; if($mailtype=="HTML"){ $header .= "Content-Type:text/html\r\n"; } $header .= "To: ".$to."\r\n"; if ($cc != "") { $header .= "Cc: ".$cc."\r\n"; } $header .= "From: $from<".$from.">\r\n"; $header .= "Subject: ".$subject."\r\n"; $header .= $additional_headers; $header .= "Date: ".date("r")."\r\n"; $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n"; list($msec, $sec) = explode(" ", microtime()); $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n"; $TO = explode(",", $this->strip_comment($to)); if ($cc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($cc))); } if ($bcc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($bcc))); } $sent = TRUE; foreach ($TO as $rcpt_to) { $rcpt_to = $this->get_address($rcpt_to); if (!$this->smtp_sockopen($rcpt_to)) { $this->log_write("Error: Cannot send email to ".$rcpt_to."\n"); $sent = FALSE; continue; } if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) { $this->log_write("E-mail has been sent to <".$rcpt_to.">\n"); } else { $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n"); $sent = FALSE; } fclose($this->sock); $this->log_write("Disconnected from remote host\n"); } echo "<br>"; echo $header; return $sent; } /* Private Functions */ function smtp_send($helo, $from, $to, $header, $body = "") { if (!$this->smtp_putcmd("HELO", $helo)) { return $this->smtp_error("sending HELO command"); } #auth if($this->auth){ if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) { return $this->smtp_error("sending HELO command"); } if (!$this->smtp_putcmd("", base64_encode($this->pass))) { return $this->smtp_error("sending HELO command"); } } # if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) { return $this->smtp_error("sending MAIL FROM command"); } if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) { return $this->smtp_error("sending RCPT TO command"); } if (!$this->smtp_putcmd("DATA")) { return $this->smtp_error("sending DATA command"); } if (!$this->smtp_message($header, $body)) { return $this->smtp_error("sending message"); } if (!$this->smtp_eom()) { return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]"); } if (!$this->smtp_putcmd("QUIT")) { return $this->smtp_error("sending QUIT command"); } return TRUE; } function smtp_sockopen($address) { if ($this->relay_host == "") { return $this->smtp_sockopen_mx($address); } else { return $this->smtp_sockopen_relay(); } } function smtp_sockopen_relay() { $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); return FALSE; } $this->log_write("Connected to relay host ".$this->relay_host."\n"); return TRUE;; } function smtp_sockopen_mx($address) { $domain = ereg_replace("^.+@([^@]+)$", "\\1", $address); if (!@getmxrr($domain, $MXHOSTS)) { $this->log_write("Error: Cannot resolve MX \"".$domain."\"\n"); return FALSE; } foreach ($MXHOSTS as $host) { $this->log_write("Trying to ".$host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Warning: Cannot connect to mx host ".$host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); continue; } $this->log_write("Connected to mx host ".$host."\n"); return TRUE; } $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n"); return FALSE; } function smtp_message($header, $body) { fputs($this->sock, $header."\r\n".$body); $this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> ")); return TRUE; } function smtp_eom() { fputs($this->sock, "\r\n.\r\n"); $this->smtp_debug(". [EOM]\n"); return $this->smtp_ok(); } function smtp_ok() { $response = str_replace("\r\n", "", fgets($this->sock, 512)); $this->smtp_debug($response."\n"); if (!ereg("^[23]", $response)) { fputs($this->sock, "QUIT\r\n"); fgets($this->sock, 512); $this->log_write("Error: Remote host returned \"".$response."\"\n"); return FALSE; } return TRUE; } function smtp_putcmd($cmd, $arg = "") { if ($arg != "") { if($cmd=="") $cmd = $arg; else $cmd = $cmd." ".$arg; } fputs($this->sock, $cmd."\r\n"); $this->smtp_debug("> ".$cmd."\n"); return $this->smtp_ok(); } function smtp_error($string) { $this->log_write("Error: Error occurred while ".$string.".\n"); return FALSE; } function log_write($message) { $this->smtp_debug($message); if ($this->log_file == "") { return TRUE; } $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message; if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) { $this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n"); return FALSE; } flock($fp, LOCK_EX); fputs($fp, $message); fclose($fp); return TRUE; } function strip_comment($address) { $comment = "\\([^()]*\\)"; while (ereg($comment, $address)) { $address = ereg_replace($comment, "", $address); } return $address; } function get_address($address) { $address = ereg_replace("([ \t\r\n])+", "", $address); $address = ereg_replace("^.*<(.+)>.*$", "\\1", $address); return $address; } function smtp_debug($message) { if ($this->debug) { echo $message."<br>"; } } function get_attach_type($image_tag) { // $filedata = array(); $img_file_con=fopen($image_tag,"r"); unset($image_data); while ($tem_buffer=AddSlashes(fread($img_file_con,filesize($image_tag)))) $image_data.=$tem_buffer; fclose($img_file_con); $filedata['context'] = $image_data; $filedata['filename']= basename($image_tag); $extension=substr($image_tag,strrpos($image_tag,"."),strlen($image_tag)-strrpos($image_tag,".")); switch($extension){ case ".gif": $filedata['type'] = "image/gif"; break; case ".gz": $filedata['type'] = "application/x-gzip"; break; case ".htm": $filedata['type'] = "text/html"; break; case ".html": $filedata['type'] = "text/html"; break; case ".jpg": $filedata['type'] = "image/jpeg"; break; case ".tar": $filedata['type'] = "application/x-tar"; break; case ".txt": $filedata['type'] = "text/plain"; break; case ".zip": $filedata['type'] = "application/zip"; break; default: $filedata['type'] = "application/octet-stream"; break; } return $filedata; } } ?>