16c01-4.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 75 行

PHP
75
字号
<?php// Prepare by setting a timezone, mail() uses this.date_default_timezone_set('America/New_York');// Save some values to send an email, these might have come from any source:$to = 'example@eliw.com';$subject = 'A sample email - Dual Format plus attachment plus inline';// Create a boundary string.  It needs to be unique (not in the text) so ...// We are going to use the sha1 algorithm to generate a 40 character string:$sep = sha1(date('r', time()));// Define the headers we want passed.$headers = "From: php@example.com\r\nX-Mailer: Custom PHP Script";// Add in our primary content boundary, and mime type specification:$headers .=     "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-{$sep}\"";// Prepare our attachment file - Read it in, encode it and split it$attached = chunk_split(base64_encode(file_get_contents('attachment.zip')));// Also now prepare our inline image - Also read, encode, split:$inline = chunk_split(base64_encode(file_get_contents('figure.gif')));// Now the body of the message.$body =<<<EOBODY--PHP-mixed-{$sep}Content-Type: multipart/alternative; boundary="PHP-alt-{$sep}"--PHP-alt-{$sep}Content-Type: text/plainHello Investors!We sold 2 million units this quarter, and expect greater sales in the next few months.  $300 of profit was earned per unit, making us themost profitable company in the market today.That's it for now.  Stay tuned for more announcements.--PHP-alt-{$sep}Content-Type: multipart/related; boundary="PHP-related-{$sep}"--PHP-related-{$sep}Content-Type: text/html<h2>Hello Investors!</h2><p>You may wish to look at the excellent numbers that we are generating:<br /><img src="cid:PHP-CID-{$sep}" /></p><p>That's it for now.  Stay tuned for more announcements.</p>--PHP-related-{$sep}Content-Type: image/gifContent-Transfer-Encoding: base64Content-ID: <PHP-CID-{$sep}>{$inline}--PHP-related-{$sep}----PHP-alt-{$sep}----PHP-mixed-{$sep}Content-Type: application/zip; name="attachment.zip"Content-Transfer-Encoding: base64Content-Disposition: attachment{$attached}--PHP-mixed-{$sep}--EOBODY;// Finally, send the emailmail($to, $subject, $body, $headers);?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?