好了下面我們來看看php發送郵件函數mail 教程,如果要使用mail函數能夠正常使用我們還得配置php.ini里面的參數哦.
- <?php
- //定義邊界線
- $boundary = uniqid( "" );
- //生成郵件頭
- $header = "From: $fromnContent-type: multipart/mixed;
- boundary="$boundary"nX-Mailer:PHPnX-Priority:3";
- //獲取附件文件的MIME類型
- $mimetype = mime_content_type('test.zip')
- //獲取附件文件的名字
- $attach = 'test.zip'
- //對附件文件進行編碼和切分
- $fp = fopen($attach, "r");
- $content = fread($fp, filesize($attach));
- $content = chunk_split( base64_encode($content) );
- //生成郵件主體
- $body ="
- --$boundary
- Content-type: text/plain; charset=iso-8859-1
- Content-transfer-encoding: 8bit
- $message
- --$boundary
- Content-Type: $mimeType; name=$filename
- Content-Disposition: attachment; filename=$filename
- Content-Transfer-Encoding: base64
- $content
- --$boundary--";
- //發送郵件
- mail( $to, $subject, $body, $header );
- ?>
新聞熱點
疑難解答