16c01-2.php

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

PHP
48
字号
<?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';// 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.  Note that they are separated by \r\n$headers = "From: php@example.com\r\nX-Mailer: Custom PHP Script";// Add in our content boundary, and mime type specification:$headers .=    "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-{$sep}\"";// The body of the message.  Use the separator with -- in front of it to //  mark the beginning of each section, and then provide the content type.//  A blank line beneath that will define the beginning of the content.  //  At the end finish with the separator again, but this time with a --//  after it as well.$body =<<<EOBODY--PHP-alt-{$sep}Content-Type: text/plainThis is our sample email messageHello World!That's it for now--PHP-alt-{$sep}Content-Type: text/html<p>This is our sample email message</p><h2>Hello World!</h2><p>That's it for now.</p>--PHP-alt-{$sep}--EOBODY;// Finally, send the emailmail($to, $subject, $body, $headers);?>

⌨️ 快捷键说明

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