Add an attachment
Add an attachment
Adding One or more attachments is simple, adding an attachment is by calling the AddAttachment method, which can be called multiple times to add more than one attachemnts.
Boolean addattachment ($ file string, string [$ c_type = ' application/eight-bit byte stream '], string [$ name =], Boolean [$ isfile = True], string [$ encoded = ' one base64 '])
Variable:
$ file: Either a variable contains the contents of a file, or the path to the file itself
$ c_type: Content type, which means, for example, the MIME type of the file. text/plain, TEXT/CSV format, application/PDF format
$ name: The name of the file that you want it to appear in the email, which should be unique
$ isfile: Whether the variable $ file is the path to the contents of the file or file
$ code: This usually should be left by default unless you know what you're doing
An attachment can be a file system stored in a variable, or in a file on the server. in this first example, I will create a small text file named ' Hello Text.txt ' instead of ' 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 ,
- ' 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
- $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 with calling AddAttachment. In this example, I'll send an e-mail 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,
' 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);
?>
http://www.bkjia.com/phpjc/444991.html www.bkjia.com true http://www.bkjia.com/phpjc/444991.html techarticle add an attachment add one or more attachments it's simple to add an attachment, By calling the AddAttachment method, this method can be called multiple times to add more than one attachemnts. Boolean ...