PearMail sends an email with an attachment. It is easy to add one or more attachments by adding an attachment. you can call the addAttachment method multiple times to add multiple attachemets. Boolean add attachment
Add an attachment
It is easy to add one or more attachments. to add attachments, you can call the addAttachment method multiple times to add multiple attachemets.
Boolean addAttachment ($ File string, string [$ c_type = 'application/eight-byte stream'], string [$ name =], Boolean [$ isfile = true], string [$ encoding = 'base64'])
Variable:
$ File: either the variable contains the content of a file or the path of the file.
$ C_type: content type, which means, for example, the MIME type of a file. Text/plain, text/CSV format, application/PDF format
$ Name: name of the file, which must be unique if you want it to appear in an email.
$ IsFile: whether the variable $ File is the path to the file or file content
$ Encoding: this should usually be left by default unless you know what you are doing
An attachment can be a file system stored in a variable or file on the server. In the first example, I changed the name of a small text file 'Your text.txt 'to 'Hello World! Also.
-
- Include ('mail. php ');
- Include ('mail/mime. php ');
-
- // Constructing the email
- $ Sender = "Leigh "; // Who your name and email address
- $ Recipient = "Leigh "; // 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 ='
This is a html message
';// HTML version of the email - $ Crlf ="N";
- $ Headers = array (
- 'From' => $ sender,
- 'Return-path' => $ sender,
- 'Subobject' => $ Subject
- );
-
- // Creating the Mime message
- $ Mime =NewMail_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
-
- $ Body = $ mime-> get ();
- $ Headers = $ mime-> headers ($ headers );
-
- // Sending the email
- $ Mail = & Mail: factory ('mail ');
- $ Mail-> send ($ recipient, $ headers, $ body );
-
?>
Add multiple attachments
As in the previous section, adding multiple attachments is rasy and calling addAttachment. In this example, I will send an email with two text attachments.
Include ('mail. php ');
Include ('mail/mime. php ');
// Constructing the email
$ Sender = "Leigh "; // Who your name and email address
$ Recipient = "Leigh "; // 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 ='
This is a html message
'; // HTML version of the email
$ Crlf = "n ";
$ Headers = array (
'From' => $ sender,
'Return-path' => $ sender,
'Subobject' => $ 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 );
?>
Adding one or more attachments to an attachment is simple. adding an attachment is done by calling the addAttachment method. this method can be called multiple times to add multiple attachemets. Boolean...