mail问题

josserchai 2002-03-12 05:51:03
我用php中的mail函数发送邮件,现在遇到以下问题:
我下载了另人调试好的Class然后直接调用,结果出现如下错误:
Warning: Server Error in d:\chaizheng\website\php\mail\mailclass.php on line 402
faile
其中402行就是mail() 的调用函数。
我上网查找,知道是SMTP服务器没配好,于是我就云下载了一个
IMail然后安装好了,并用IMail在我们intranet内和向internet发送邮件
均成功。在php.ini中我是这么设置的:
[mail function]
; For Win32 only.
SMTP = wk102.chief.com

; For Win32 only.
sendmail_from = root@wk102.chief.com
其中wk102是我的机名,chief.com是域名。
但在用PHP发邮件时出错,也收不到邮件,请问为何?
多谢?
PS:
我的程序为:

<?php
require('9_1.php');//9_1.php见后
$attachment=fread(fopen("test.jpg","r"),filesize("test.jpg"));
$mail=new mime_mail();
$mail->from="josser@263.net";
$mail->headers="Errors-To:josser@263.net";
$mail->to="josserchai@yahoo.com";
$mail->subject="Hi......test";
$mail->body="Hello ,please happy ,this is sent by php";
$mail->add_attachment("$attachment","test.jpg","image/jpeg");
$mail->send();
?>

//9_1.php

<?php
class mime_mail
{
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;

function mime_mail()
{
$this->parts=array();
$this->to="";
$this->from="";
$this->subject="";
$this->body="";
$this->headers="";
}
//增加一个附件
function add_attachment($message,$name="",$ctype="application/octet-stream")
{
$this->parts[]=array("ctype"=>$ctype,"message"=>$message,"encode"=>$encode,"name"=>$name);
}
//构造多部分邮件的正文部分
function build_message($part)
{
$message=$part["message"];
$message=chunk_split(base64_encode($message));
$encoding="base64";
return "content-Type:".$part["ctype"].($part["name"]?";name=\"".$part["name"]."\"":"")."\nContent-Transfer-Encoding:$encoding\n\n$message\n";
}
//建立多部分邮件
function build_multipart()
{
$boundary="b".md5(uniqid(time()));
$multipart="Content-Type:multipart/mixed;boundary=$boundary\n\nThis is a MIME encoded message.\n\n--$boundary";
for($i=sizeof($this->parts)-1;$i>=0;$i--)
{
$multipart .="\n".$this->build_message($this->parts[$i])."--$boundary";
}
return $multipart.="--\n";
}
//发送邮件,最后调用
function send()
{
$mime="";
if(!empty($this->from))
$mime.="From:".$this->from."\n";
if(!empty($this->headers))
$mime.=$this->headers."\n";
if(!empty($this->body))
$this->add_attachment($this->body,"","text/plain");
$mime.="MIME-Version:1.0\n".$this->build_multipart();
mail($this->to,$this->subject," ",$mime);
}
}?>

...全文
39 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
SimonDW 2002-03-12
  • 打赏
  • 举报
回复
用你机器的ip代替wk102.chief.com
除非你确定你的机器ip被dns服务器解析了。
qsnake 2002-03-12
  • 打赏
  • 举报
回复
出错提示是什么,把smtp改成IP地址看看

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧