日期:2014-01-11  浏览次数:20461 次

sendmail.php4

<?
//加载发送附件的类
require('html_mime_mail.inc');

if($update!=""){  //如果带附件
    
    //上传附件
    if(!file_exists("c:/ftptmp/".$myfile_name)){
        if(copy($myfile,"c:/ftptmp/".$myfile_name)){
            //读取附件
            $attachment = fread($fp = fopen("c:/ftptmp/".$myfile_name, 'r'), filesize($myfile));
            fclose($fp);
            //unlink("c:/ftptmp/".$myfile_name);删掉
        }
        else {
            echo "上传文件失败!";
            exit();
        }
    }
    else{
        echo "文件重名!";
        exit();
    }
    
    
    //新建一个类的实例,并加入附件
    $mail = new html_mime_mail();
    $mail->add_attachment($attachment, $myfile_name, 'application/octet-stream');
    
    /*---------------------这段示范了如何发HTML信件---------------------------------------
    $filename = 'background.gif';
    $backgrnd = fread($fp = fopen($filename, 'r'), filesize($filename));
    fclose($fp);

    $text = 'This is a test.';
    $html = '<HTML><BODY BACKGROUND="background.gif"><FONT FACE="Verdana, Arial" COLOR="#FF0000">    Success!</FONT><P></BODY></HTML>';
    
    $mail->add_html_image($backgrnd, 'background.gif', 'image/gif');
    $mail->add_html($html, $text);
    -------------------------------------------------------------------------------------*/
    
    //读取正文,将信件封装并发送
    $mail->body=$bodytext;
    $mail->build_message();

    $backvalue=$mail->send(' ',$receivemailbox,' ',$sendmailbox,$subject,' ');
    
    //发送提示信息
    echo "<script     language=javascript>alert('发信OK,按确定返回!');window.location='default.htm'</script>";
}
else{  //如果不带附件
    $backvalue=mail($receivemailbox,$subject,$bodytext,"From:" . $sendmailbox . "\nReply-To:" . $sendmailbox . "\nX-Mailer: PHP/" . phpversion());
    
    if ($result) {
        echo "<script language=javascript>alert('发信OK,按确定返回!');window.location='default.htm'</script>";
    }
    else{
        echo "<script language=javascript>backvalue=window.confirm('发信失败!可能是服务器太忙!是否要重发?');if(backvalue){location.reload()}else{window.location='default.htm'}</script>";
  &