$mailSubject= "This is a test.";
$mailBody = "Hello:<br>This is a test.<br>";
$mailBody = "<a href=http://www.mistruster.com/>Mistruster</a>";
$mailTo = "test@mai.cxc.cc";
$mailHeader = "From: test@mai.cxc.cc\n";
$mailHeader.= "Content-Type:text/html;\ncharset=gb2312;\n";
mail($mailTo,$mailSubject,$mailBody,$mailHeader);
19 个解决方案
#1
php教学?
#2
这位兄弟想说什么?
想教大家MAIL的使用吗?
想教大家MAIL的使用吗?
#3
哦,原来还有个帖子
#4
基本原理就是这样,如果看了邮件的源码就知道怎么发邮件了:
http://expert.csdn.net/Expert/topic/2052/2052411.xml
---
function getRandomBoundary($offset = 0)
{
srand(time()+$offset);
$Boundary = md5(rand());
$Boundary = strtoupper($Boundary);
return $Boundary;
}
function getContentType($inFileName)
{
$inFileName = basename($inFileName);
if(strrchr($inFileName, ".") == false)
{
return "application/octet-stream";
}
$extension = strrchr($inFileName, ".");
switch($extension)
{
case ".gz": return "application/x-gzip";
case ".pdf": return "application/pdf";
case ".tar": return "application/x-tar";
case ".zip": return "application/zip";
case ".doc": return "application/msword";
case ".mdb": return "application/msaccess";
case ".mp3": return "audio/mpeg";
case ".mid": return "audio/mid";
case ".gif": return "image/gif";
case ".jpg": return "image/jpeg";
case ".htm": return "text/html";
case ".html": return "text/html";
case ".txt": return "text/plain";
default: return "application/octet-stream";
}
return "application/octet-stream";
}
function getAttachment($inFileLocation, $FileName)
{
$outAttachmentHeader = "";
$contentType = getContentType($FileName);
if(ereg("text",$contentType))
{
$outAttachment .= "Content-Type:".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName). "\"\n";
$outAttachment .= "Content-Transfer-Encoding: 7bit\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName)."\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
else
{
$outAttachment .= "Content-Type: ".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName)."\"\n";
$outAttachment .= "Content-Transfer-Encoding: base64\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName). "\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=base64_encode($outAttachmentBody);
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
return false;
}
$bodyBoundary=getRandomBoundary(1);
$bodyBoundary2=getRandomBoundary(2);
$mailTo = "test@mai.cxc.cc";
//发邮件,带附件除了
$mailHeader = "From: test@mai.cxc.cc\n";
$mailHeader.="Mime-Version:1.0\n";
$mailHeader.="Content-Type:multipart/mixed;\n\t";
$mailHeader.="boundary=\"$bodyBoundary\"\n\n";
//剩下的都放到$mailBody里:
$mailBody ="This is a multi-part message in MIME format.\n\n";
$mailBody.="--$bodyBoundary\n";
$mailBody.="Content-Type: multipart/alternative;\n\t";
$mailBody.="boundary=\"".$bodyBoundary2."\"\n\n\n";
$Body = chunk_split(base64_encode($Body));//邮件正文
$mailBody.="--$bodyBoundary2\n";
$mailBody.="Content-Type: text/html;\nContent-Transfer-Encoding: base64\n\n";
$mailBody.=$Body."\n\n";
$mailBody.="--".$bodyBoundary2."--\n\n";//正文结束
if(!empty($_FILES["attach"]["name"]))
{
$mailBody.="--".$bodyBoundary."\n";
$mailBody.=getAttachment($attach, $_FILES['attach']['name'])."\n";
//邮件附件
}
$mailBody.="--".$bodyBoundary."--"."\n";//邮件结束
mail($mailTo,$mailSubject,$mailBody,$mailHeader);//发送……
http://expert.csdn.net/Expert/topic/2052/2052411.xml
---
function getRandomBoundary($offset = 0)
{
srand(time()+$offset);
$Boundary = md5(rand());
$Boundary = strtoupper($Boundary);
return $Boundary;
}
function getContentType($inFileName)
{
$inFileName = basename($inFileName);
if(strrchr($inFileName, ".") == false)
{
return "application/octet-stream";
}
$extension = strrchr($inFileName, ".");
switch($extension)
{
case ".gz": return "application/x-gzip";
case ".pdf": return "application/pdf";
case ".tar": return "application/x-tar";
case ".zip": return "application/zip";
case ".doc": return "application/msword";
case ".mdb": return "application/msaccess";
case ".mp3": return "audio/mpeg";
case ".mid": return "audio/mid";
case ".gif": return "image/gif";
case ".jpg": return "image/jpeg";
case ".htm": return "text/html";
case ".html": return "text/html";
case ".txt": return "text/plain";
default: return "application/octet-stream";
}
return "application/octet-stream";
}
function getAttachment($inFileLocation, $FileName)
{
$outAttachmentHeader = "";
$contentType = getContentType($FileName);
if(ereg("text",$contentType))
{
$outAttachment .= "Content-Type:".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName). "\"\n";
$outAttachment .= "Content-Transfer-Encoding: 7bit\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName)."\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
else
{
$outAttachment .= "Content-Type: ".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName)."\"\n";
$outAttachment .= "Content-Transfer-Encoding: base64\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName). "\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=base64_encode($outAttachmentBody);
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
return false;
}
$bodyBoundary=getRandomBoundary(1);
$bodyBoundary2=getRandomBoundary(2);
$mailTo = "test@mai.cxc.cc";
//发邮件,带附件除了
$mailHeader = "From: test@mai.cxc.cc\n";
$mailHeader.="Mime-Version:1.0\n";
$mailHeader.="Content-Type:multipart/mixed;\n\t";
$mailHeader.="boundary=\"$bodyBoundary\"\n\n";
//剩下的都放到$mailBody里:
$mailBody ="This is a multi-part message in MIME format.\n\n";
$mailBody.="--$bodyBoundary\n";
$mailBody.="Content-Type: multipart/alternative;\n\t";
$mailBody.="boundary=\"".$bodyBoundary2."\"\n\n\n";
$Body = chunk_split(base64_encode($Body));//邮件正文
$mailBody.="--$bodyBoundary2\n";
$mailBody.="Content-Type: text/html;\nContent-Transfer-Encoding: base64\n\n";
$mailBody.=$Body."\n\n";
$mailBody.="--".$bodyBoundary2."--\n\n";//正文结束
if(!empty($_FILES["attach"]["name"]))
{
$mailBody.="--".$bodyBoundary."\n";
$mailBody.=getAttachment($attach, $_FILES['attach']['name'])."\n";
//邮件附件
}
$mailBody.="--".$bodyBoundary."--"."\n";//邮件结束
mail($mailTo,$mailSubject,$mailBody,$mailHeader);//发送……
#5
以上虽不是完整的代码,但也可以发邮件了。(带附件)
---
我只是想介绍发邮件的基本原理;
哎,我就是那么弱智,不会好了……
---
我只是想介绍发邮件的基本原理;
哎,我就是那么弱智,不会好了……
#6
没懂,收藏先!
#7
我有一点糊涂.
#8
to: Mistruster(弱智d)
你第二次粘贴的是利用mime协议发送附件的一个大类,主要是生成代码。包括头,主题等。发送附件是先将附件编码,一般是base64 或者7 bit,接受到后再解码。
我也是刚学了点,共同进步~
关于邮件头的资料,建议到http://www.yesky.com/SoftChannel/72347873798258688/20030526/1703237.shtml看看
你第二次粘贴的是利用mime协议发送附件的一个大类,主要是生成代码。包括头,主题等。发送附件是先将附件编码,一般是base64 或者7 bit,接受到后再解码。
我也是刚学了点,共同进步~
关于邮件头的资料,建议到http://www.yesky.com/SoftChannel/72347873798258688/20030526/1703237.shtml看看
#9
http://www.mistruster.com/mail/
我做的电子邮件系统,
我现在在研究怎么发送真正的多媒体邮件,
带背景音乐比较容易,就是在附件里放个mid文件,然后在邮件正文里做连接……
可是一般的邮件系统好像不能比较好的接收……
我做的电子邮件系统,
我现在在研究怎么发送真正的多媒体邮件,
带背景音乐比较容易,就是在附件里放个mid文件,然后在邮件正文里做连接……
可是一般的邮件系统好像不能比较好的接收……
#10
http://prdownloads.sourceforge.net/phpmailer/phpmailer-1.70.tar.gz?download
试试这个对你有没有帮助!
试试这个对你有没有帮助!
#11
没有人补充了吗?
#12
Call to undefined function: mail()
我使用出现上面的错误,请问,是什么原因呢?谢谢
php4.3.0+apache1.3.28+redhat 8.0+mysql 4.0.15.
我使用出现上面的错误,请问,是什么原因呢?谢谢
php4.3.0+apache1.3.28+redhat 8.0+mysql 4.0.15.
#13
学习!
#14
不管了,接分
#15
还有利用socket发信的类
#16
up up up again
#17
up
up
up
#18
hao !
#19
大家们,谁能帮我写一个需要难的smtp发信件的程序(信件可以是html)格式,我这里有原程序,但是只能发文本程序,谁能帮我改一下,能发html格式的,谢谢啦~~
------------------------------------------------
function sendmail($to,$subject, $message )
{
$smtp = "211.152.33.113"; //您的SMTP 服务器供应商,可以是域名或IP地址
$check = 1; //SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
if ($check) {
$username = "mail@fzc.cn"; //您的email帐号名称
$password = "8886898"; //您的email密码
}
$s_from = "mail@fzc.cn"; //此email 必需是发信服务器上的email
//连接服务器
$fp = fsockopen ( $smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );
$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息:".$lastmessage.__LINE__;
//HELO
$yourname = "mail";
if($check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";
fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )
break;
}
//身份验证
if ($check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息$lastmessage".__LINE__;
}
//FROM:
$lastact="MAIL FROM: $s_from" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//TO:
$lastact="RCPT TO: $to" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息$lastmessage".__LINE__;
//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;
//处理From头
$head="From: mail@fzc.cn\r\n";
$message = $head.$message;
//处理To头
$head="To: $to\r\n";
$message = $head.$message;
//加上结束串
$message .= "\r\n.\r\n";
//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";
fputs($fp,$lastace);
fclose($fp);
return 0;
}
------------------------------------------------
function sendmail($to,$subject, $message )
{
$smtp = "211.152.33.113"; //您的SMTP 服务器供应商,可以是域名或IP地址
$check = 1; //SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
if ($check) {
$username = "mail@fzc.cn"; //您的email帐号名称
$password = "8886898"; //您的email密码
}
$s_from = "mail@fzc.cn"; //此email 必需是发信服务器上的email
//连接服务器
$fp = fsockopen ( $smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );
$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息:".$lastmessage.__LINE__;
//HELO
$yourname = "mail";
if($check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";
fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )
break;
}
//身份验证
if ($check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息$lastmessage".__LINE__;
}
//FROM:
$lastact="MAIL FROM: $s_from" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//TO:
$lastact="RCPT TO: $to" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息$lastmessage".__LINE__;
//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;
//处理From头
$head="From: mail@fzc.cn\r\n";
$message = $head.$message;
//处理To头
$head="To: $to\r\n";
$message = $head.$message;
//加上结束串
$message .= "\r\n.\r\n";
//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";
fputs($fp,$lastace);
fclose($fp);
return 0;
}
#20
#1
php教学?
#2
这位兄弟想说什么?
想教大家MAIL的使用吗?
想教大家MAIL的使用吗?
#3
哦,原来还有个帖子
#4
基本原理就是这样,如果看了邮件的源码就知道怎么发邮件了:
http://expert.csdn.net/Expert/topic/2052/2052411.xml
---
function getRandomBoundary($offset = 0)
{
srand(time()+$offset);
$Boundary = md5(rand());
$Boundary = strtoupper($Boundary);
return $Boundary;
}
function getContentType($inFileName)
{
$inFileName = basename($inFileName);
if(strrchr($inFileName, ".") == false)
{
return "application/octet-stream";
}
$extension = strrchr($inFileName, ".");
switch($extension)
{
case ".gz": return "application/x-gzip";
case ".pdf": return "application/pdf";
case ".tar": return "application/x-tar";
case ".zip": return "application/zip";
case ".doc": return "application/msword";
case ".mdb": return "application/msaccess";
case ".mp3": return "audio/mpeg";
case ".mid": return "audio/mid";
case ".gif": return "image/gif";
case ".jpg": return "image/jpeg";
case ".htm": return "text/html";
case ".html": return "text/html";
case ".txt": return "text/plain";
default: return "application/octet-stream";
}
return "application/octet-stream";
}
function getAttachment($inFileLocation, $FileName)
{
$outAttachmentHeader = "";
$contentType = getContentType($FileName);
if(ereg("text",$contentType))
{
$outAttachment .= "Content-Type:".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName). "\"\n";
$outAttachment .= "Content-Transfer-Encoding: 7bit\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName)."\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
else
{
$outAttachment .= "Content-Type: ".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName)."\"\n";
$outAttachment .= "Content-Transfer-Encoding: base64\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName). "\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=base64_encode($outAttachmentBody);
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
return false;
}
$bodyBoundary=getRandomBoundary(1);
$bodyBoundary2=getRandomBoundary(2);
$mailTo = "test@mai.cxc.cc";
//发邮件,带附件除了
$mailHeader = "From: test@mai.cxc.cc\n";
$mailHeader.="Mime-Version:1.0\n";
$mailHeader.="Content-Type:multipart/mixed;\n\t";
$mailHeader.="boundary=\"$bodyBoundary\"\n\n";
//剩下的都放到$mailBody里:
$mailBody ="This is a multi-part message in MIME format.\n\n";
$mailBody.="--$bodyBoundary\n";
$mailBody.="Content-Type: multipart/alternative;\n\t";
$mailBody.="boundary=\"".$bodyBoundary2."\"\n\n\n";
$Body = chunk_split(base64_encode($Body));//邮件正文
$mailBody.="--$bodyBoundary2\n";
$mailBody.="Content-Type: text/html;\nContent-Transfer-Encoding: base64\n\n";
$mailBody.=$Body."\n\n";
$mailBody.="--".$bodyBoundary2."--\n\n";//正文结束
if(!empty($_FILES["attach"]["name"]))
{
$mailBody.="--".$bodyBoundary."\n";
$mailBody.=getAttachment($attach, $_FILES['attach']['name'])."\n";
//邮件附件
}
$mailBody.="--".$bodyBoundary."--"."\n";//邮件结束
mail($mailTo,$mailSubject,$mailBody,$mailHeader);//发送……
http://expert.csdn.net/Expert/topic/2052/2052411.xml
---
function getRandomBoundary($offset = 0)
{
srand(time()+$offset);
$Boundary = md5(rand());
$Boundary = strtoupper($Boundary);
return $Boundary;
}
function getContentType($inFileName)
{
$inFileName = basename($inFileName);
if(strrchr($inFileName, ".") == false)
{
return "application/octet-stream";
}
$extension = strrchr($inFileName, ".");
switch($extension)
{
case ".gz": return "application/x-gzip";
case ".pdf": return "application/pdf";
case ".tar": return "application/x-tar";
case ".zip": return "application/zip";
case ".doc": return "application/msword";
case ".mdb": return "application/msaccess";
case ".mp3": return "audio/mpeg";
case ".mid": return "audio/mid";
case ".gif": return "image/gif";
case ".jpg": return "image/jpeg";
case ".htm": return "text/html";
case ".html": return "text/html";
case ".txt": return "text/plain";
default: return "application/octet-stream";
}
return "application/octet-stream";
}
function getAttachment($inFileLocation, $FileName)
{
$outAttachmentHeader = "";
$contentType = getContentType($FileName);
if(ereg("text",$contentType))
{
$outAttachment .= "Content-Type:".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName). "\"\n";
$outAttachment .= "Content-Transfer-Encoding: 7bit\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName)."\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
else
{
$outAttachment .= "Content-Type: ".$contentType. ";\n\t";
$outAttachment .= "name=\"".basename($FileName)."\"\n";
$outAttachment .= "Content-Transfer-Encoding: base64\n";
$outAttachment .= "Content-Disposition: attachment;\n\t";
$outAttachment .= "filename=\"".basename($FileName). "\"\n\n\n";
$fp=fopen($inFileLocation,"r");
if($fp)
{
$outAttachmentBody=fread($fp,filesize($inFileLocation));
$outAttachmentBody=base64_encode($outAttachmentBody);
$outAttachmentBody=chunk_split($outAttachmentBody);
fclose($fp);
}
$outAttachment.=$outAttachmentBody."\n";
return $outAttachment;
}
return false;
}
$bodyBoundary=getRandomBoundary(1);
$bodyBoundary2=getRandomBoundary(2);
$mailTo = "test@mai.cxc.cc";
//发邮件,带附件除了
$mailHeader = "From: test@mai.cxc.cc\n";
$mailHeader.="Mime-Version:1.0\n";
$mailHeader.="Content-Type:multipart/mixed;\n\t";
$mailHeader.="boundary=\"$bodyBoundary\"\n\n";
//剩下的都放到$mailBody里:
$mailBody ="This is a multi-part message in MIME format.\n\n";
$mailBody.="--$bodyBoundary\n";
$mailBody.="Content-Type: multipart/alternative;\n\t";
$mailBody.="boundary=\"".$bodyBoundary2."\"\n\n\n";
$Body = chunk_split(base64_encode($Body));//邮件正文
$mailBody.="--$bodyBoundary2\n";
$mailBody.="Content-Type: text/html;\nContent-Transfer-Encoding: base64\n\n";
$mailBody.=$Body."\n\n";
$mailBody.="--".$bodyBoundary2."--\n\n";//正文结束
if(!empty($_FILES["attach"]["name"]))
{
$mailBody.="--".$bodyBoundary."\n";
$mailBody.=getAttachment($attach, $_FILES['attach']['name'])."\n";
//邮件附件
}
$mailBody.="--".$bodyBoundary."--"."\n";//邮件结束
mail($mailTo,$mailSubject,$mailBody,$mailHeader);//发送……
#5
以上虽不是完整的代码,但也可以发邮件了。(带附件)
---
我只是想介绍发邮件的基本原理;
哎,我就是那么弱智,不会好了……
---
我只是想介绍发邮件的基本原理;
哎,我就是那么弱智,不会好了……
#6
没懂,收藏先!
#7
我有一点糊涂.
#8
to: Mistruster(弱智d)
你第二次粘贴的是利用mime协议发送附件的一个大类,主要是生成代码。包括头,主题等。发送附件是先将附件编码,一般是base64 或者7 bit,接受到后再解码。
我也是刚学了点,共同进步~
关于邮件头的资料,建议到http://www.yesky.com/SoftChannel/72347873798258688/20030526/1703237.shtml看看
你第二次粘贴的是利用mime协议发送附件的一个大类,主要是生成代码。包括头,主题等。发送附件是先将附件编码,一般是base64 或者7 bit,接受到后再解码。
我也是刚学了点,共同进步~
关于邮件头的资料,建议到http://www.yesky.com/SoftChannel/72347873798258688/20030526/1703237.shtml看看
#9
http://www.mistruster.com/mail/
我做的电子邮件系统,
我现在在研究怎么发送真正的多媒体邮件,
带背景音乐比较容易,就是在附件里放个mid文件,然后在邮件正文里做连接……
可是一般的邮件系统好像不能比较好的接收……
我做的电子邮件系统,
我现在在研究怎么发送真正的多媒体邮件,
带背景音乐比较容易,就是在附件里放个mid文件,然后在邮件正文里做连接……
可是一般的邮件系统好像不能比较好的接收……
#10
http://prdownloads.sourceforge.net/phpmailer/phpmailer-1.70.tar.gz?download
试试这个对你有没有帮助!
试试这个对你有没有帮助!
#11
没有人补充了吗?
#12
Call to undefined function: mail()
我使用出现上面的错误,请问,是什么原因呢?谢谢
php4.3.0+apache1.3.28+redhat 8.0+mysql 4.0.15.
我使用出现上面的错误,请问,是什么原因呢?谢谢
php4.3.0+apache1.3.28+redhat 8.0+mysql 4.0.15.
#13
学习!
#14
不管了,接分
#15
还有利用socket发信的类
#16
up up up again
#17
up
up
up
#18
hao !
#19
大家们,谁能帮我写一个需要难的smtp发信件的程序(信件可以是html)格式,我这里有原程序,但是只能发文本程序,谁能帮我改一下,能发html格式的,谢谢啦~~
------------------------------------------------
function sendmail($to,$subject, $message )
{
$smtp = "211.152.33.113"; //您的SMTP 服务器供应商,可以是域名或IP地址
$check = 1; //SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
if ($check) {
$username = "mail@fzc.cn"; //您的email帐号名称
$password = "8886898"; //您的email密码
}
$s_from = "mail@fzc.cn"; //此email 必需是发信服务器上的email
//连接服务器
$fp = fsockopen ( $smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );
$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息:".$lastmessage.__LINE__;
//HELO
$yourname = "mail";
if($check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";
fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )
break;
}
//身份验证
if ($check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息$lastmessage".__LINE__;
}
//FROM:
$lastact="MAIL FROM: $s_from" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//TO:
$lastact="RCPT TO: $to" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息$lastmessage".__LINE__;
//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;
//处理From头
$head="From: mail@fzc.cn\r\n";
$message = $head.$message;
//处理To头
$head="To: $to\r\n";
$message = $head.$message;
//加上结束串
$message .= "\r\n.\r\n";
//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";
fputs($fp,$lastace);
fclose($fp);
return 0;
}
------------------------------------------------
function sendmail($to,$subject, $message )
{
$smtp = "211.152.33.113"; //您的SMTP 服务器供应商,可以是域名或IP地址
$check = 1; //SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
if ($check) {
$username = "mail@fzc.cn"; //您的email帐号名称
$password = "8886898"; //您的email密码
}
$s_from = "mail@fzc.cn"; //此email 必需是发信服务器上的email
//连接服务器
$fp = fsockopen ( $smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );
$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息:".$lastmessage.__LINE__;
//HELO
$yourname = "mail";
if($check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";
fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )
break;
}
//身份验证
if ($check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息$lastmessage".__LINE__;
}
//FROM:
$lastact="MAIL FROM: $s_from" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//TO:
$lastact="RCPT TO: $to" . "\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息$lastmessage".__LINE__;
//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息$lastmessage".__LINE__;
//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;
//处理From头
$head="From: mail@fzc.cn\r\n";
$message = $head.$message;
//处理To头
$head="To: $to\r\n";
$message = $head.$message;
//加上结束串
$message .= "\r\n.\r\n";
//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";
fputs($fp,$lastace);
fclose($fp);
return 0;
}