程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> Pear Mail 發送郵件帶附件

Pear Mail 發送郵件帶附件

編輯:關於PHP編程

添加附件
添加一個附件
添加一或多個附件很簡單,添加附件,是通過調用addAttachment方法,這種方法可以多次調用添加多個attachemnts。

布爾addAttachment($文件的字符串,字符串[$ c_type ='應用程序/八位字節流'],串[$名稱=],布爾[$ isfile =真],字符串[$編碼='一個base64'])
變量:

$文件:要麼變量包含一個文件的內容,或文件本身的路徑
$ c_type:內容類型,這意味著,例如文件的MIME類型。
text / plain的,文字/ CSV格式,應用/ PDF格式
$名稱:該文件的名稱,您希望它出現在電子郵件,這應該是唯一的
$ isFile:是否變量$文件是對文件或文件的內容的路徑
$編碼:這通常應為默認離開,除非你知道你在做什麼
附件可以是在一個變量,或在服務器上的文件中存儲的文件系統。在這第一個例子中,我將建立一個小型文本文件名為'你好text.txt'改為'你好世界!也。

  1. <?
  2.         include('Mail.php');
  3.         include('Mail/mime.php');
  4.  
  5.         // Constructing the email
  6.         $sender = "Leigh <leigh@no_spam.net>";                              // Who your name and email address
  7.         $recipient = "Leigh <leigh@no_spam.net>";                           // The Recipients name and email address
  8.         $subject = "Test Email";                                            // Subject for the email
  9.         $text = 'This is a text message.';                                  // Text version of the email
  10.         $html = '<html><body><p>This is a html message</p></body></html>';  // HTML version of the email
  11.         $crlf = "n";
  12.         $headers = array(
  13.                         'From'          => $sender,
  14.                         'Return-Path'   => $sender,
  15.                         'Subject'       => $subject
  16.                         );
  17.  
  18.         // Creating the Mime message
  19.         $mime = new Mail_mime($crlf);
  20.  
  21.         // Setting the body of the email
  22.         $mime->setTXTBody($text);
  23.         $mime->setHTMLBody($html);
  24.  
  25.         // Add an attachment
  26.         $file = "Hello World!";                                      // Content of the file
  27.         $file_name = "Hello text.txt";                               // Name of the Attachment
  28.         $content_type = "text/plain";                                // Content type of the file
  29.         $mime->addAttachment ($file, $content_type, $file_name, 0);  // Add the attachment to the email
  30.  
  31.         $body = $mime->get();
  32.         $headers = $mime->headers($headers);
  33.  
  34.         // Sending the email
  35.         $mail =& Mail::factory('mail');
  36.         $mail->send($recipient, $headers, $body);
  37. ?>

    添加多個附件
    正如上一節,添加多個附件是rasy與調用addAttachment了。在這個例子中,我會發送一個帶有兩個文本附件的電子郵件。

    <?
            include('Mail.php');
            include('Mail/mime.php');
     
            // Constructing the email
            $sender = "Leigh <leigh@no_spam.net>";                              // Who your name and email address
            $recipient = "Leigh <leigh@no_spam.net>";                           // The Recipients name and email address
            $subject = "Test Email";                                            // Subject for the email
            $text = 'This is a text message.';                                  // Text version of the email
            $html = '<html><body><p>This is a html message</p></body></html>';  // HTML version of the email
            $crlf = "n";
            $headers = array(
                            'From'          => $sender,
                            'Return-Path'   => $sender,
                            'Subject'       => $subject
                            );
     
            // Creating the Mime message
            $mime = new Mail_mime($crlf);
     
            // Setting the body of the email
            $mime->setTXTBody($text);
            $mime->setHTMLBody($html);
     
            // Add an attachment
            $file = "Hello World!";                                      // Content of the file
            $file_name = "Hello text.txt";                               // Name of the Attachment
            $content_type = "text/plain";                                // Content type of the file
            $mime->addAttachment ($file, $content_type, $file_name, 0);  // Add the attachment to the email
     
            // Add a second attachment
            $file = "Hello World! Again :)";                             // Content of the file
            $file_name = "Hello text 2.txt";                             // Name of the Attachment
            $content_type = "text/plain";                                // Content type of the file
            $mime->addAttachment ($file, $content_type, $file_name, 0);  // Add the attachment to the email
     
            $body = $mime->get();
            $headers = $mime->headers($headers);
     
            // Sending the email
            $mail =& Mail::factory('mail');
            $mail->send($recipient, $headers, $body);
    ?>


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved