打印

[PHP教程] php写的发送附件的程序(一)

php写的发送附件的程序(一)


heyes
   
   <?
  error_reporting(63);
  include('class.html_mime_mail.inc');
   
  /***************************************
  ** example of usage.
  ***************************************/
  /***************************************
  ** read the file background.gif into
  ** $backgrnd.
  ***************************************/
  $filename = 'background.gif';
  $backgrnd = fread($fp = fopen($filename, 'r'), filesize($filename));
  fclose($fp);
   
  /***************************************
  ** read the file test.zip into $attachment.
  ***************************************/
  $filename = 'example.zip';
  $attachment = fread($fp = fopen($filename, 'r'), filesize($filename));
  fclose($fp);
   
  /***************************************
  ** create the mail object. optional headers
  ** argument. do not put from: here, this
  ** will be added when $mail->send
  ***************************************/
  $mail = new html_mime_mail("x-mailer: html mime mail class\r\n");
   
  /***************************************
  ** if sending an html email, then these
  ** two variables specify the text and
  ** html versions of the mail. don't
  ** have to be named as these are. just
  ** make sure the names tie in to the
  ** $mail->add_html() command further down.
  ***************************************/
  $text = 'this is a test.';
  $html = '<html><body background="background.gif"><font face="verdana, arial" color="#ff0000">    success!</font><p></body></html>';
   
  /***************************************

  ** add the text, html and embedded images.
  ** each embedded image has to be added
  ** using $mail->add_html_image() before
  ** calling $mail->add_html(). the name
  ** of the image should match exactly
  ** (case-sensitive) to the name in the html.
  ***************************************/
  $mail->add_html_image($backgrnd, 'background.gif', 'image/gif');
  $mail->add_html($html, $text);
   
  /***************************************
  ** if not sending an html email, then

  ** this is used to set the plain text
  ** body of the email.
  ***************************************/
  // $mail->body = 'fsss';
   
  /***************************************
  ** this is used to add an attachment to
  ** the email.
  ***************************************/
  $mail->add_attachment($attachment, 'example.zip', 'application/octet-stream');
   
  /***************************************
  ** builds the message.
  ***************************************/
  $mail->build_message();
   
  /***************************************
  ** sends the message. $mail->build_message()
  ** is seperate to $mail->send so that the
  ** same email can be sent many times to
  ** differing recipients simply by putting
  ** $mail->send() in a loop.
  ***************************************/

  $mail->send('','szw@phpexe.com', 'from name', 'szw@phpexe.com', 'subject','');
   
  /***************************************
  ** debug stuff. entirely unnecessary.
  ***************************************/
  echo '<pre>';
  echo $mail->mime;
  echo '</pre>';
  ?>
   



TOP

返回顶部
AYBlue

Processed in 0.053174 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-8 11:44 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP