'."\n"; // +----------------------------------------------------------------------+ // | Author: Yan Morin // | http://membres.lycos.fr/yansanmo/ // +----------------------------------------------------------------------+ // | Historic: // | ADD FILE MODIFICATION: 2003/03/31 // +----------------------------------------------------------------------+ // FIND CODE INSPIRATION IN // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Richard Heyes | // +----------------------------------------------------------------------+ // HEADERS: // Add message ID header define (CRLF, "\n"); define (MAIL_MIMEPART_CRLF, "\n"); $tabInfos = array('TO','GOTOURL','REPLYTO','SUBJECT'); $strTo = ''; $strRedirect = ''; $strFrom = ''; $strSubject = ''; $headers = ''; $strMsg = ''; // prepare headers srand((double)microtime()*10000000); $message_id = sprintf('<%s.%s@lycos.fr>', base_convert(time(), 10, 36), base_convert(rand(), 10, 36) ); $headers = array(); $headers['Message-ID'] = $message_id; $headers['MIME-version'] = '1.0'; // prepare mail function parameters... if ( isset($_POST['TO']) ) { $strTo = $_POST['TO']; } if ( isset($_POST['GOTOURL']) ) { $strRedirect = $_POST['GOTOURL']; } if ( isset($_POST['FROM']) ) { $strFrom = $_POST['FROM']; } if ( isset($_POST['SUBJECT']) ) { $strSubject = $_POST['SUBJECT']; } // reply-to if we put one.. if ( isset($_POST['REPLYTO']) ) { $headers['Reply-To'] = $_POST['REPLYTO']; } else if ( $strFrom!='' ) { $headers['Reply-To'] = $strFrom; } /* for constructing message */ foreach ($_POST as $key=>$value) { if ( !in_array($key,$tabInfos) ) { $strMsg .= $key . '=' . $value . "\n"; } } $strMsg = stripslashes($strMsg); // add 2003/04/02 17:47 // with or without files? if (!count($_FILES)) { // send text-format email // construct headers foreach ($this->headers as $name => $value) { $headers[] = $name . ': ' . $this->_encodeHeader($value); } // end send text-only message mail($strTo,$strSubject,$strMsg, implode(CRLF, $headers)); } else { // send file sendMailWithFile($strTo, $strSubject, $strMsg, $headers); } ?> Envoi de message '."\n"; } ?>

Envoi du message

DE:

À:

SUJET:

'); function sendMailWithFile($to, $subject, $message, $headers) { $boundary = 'Boundary_' . md5(uniqid(rand()) . microtime()); $headers['Content-type'] = 'multipart/mixed; boundary="'.$boundary.'"'; $output = 'This is a multi-part message in MIME format.' . CRLF.CRLF; $output .= '--'.$boundary.MAIL_MIMEPART_CRLF; $output .= 'Content-type: text/plain; charset="ISO-8859-1"; format=flowed'.CRLF; $output .= 'Content-transfer-encoding: 7BIT'.CRLF.CRLF; $output .= $message . MAIL_MIMEPART_CRLF; /* loop for each files uploaded */ foreach ($_FILES as $aFile) { if ( is_uploaded_file($aFile['tmp_name']) ) { $filename = $aFile['name']; $filepath = $aFile['tmp_name']; } $output .= CRLF.'--'.$boundary.MAIL_MIMEPART_CRLF. 'Content-type: application/octet-stream; name="'.$filename.'"'.CRLF. 'Content-transfer-encoding: base64'.CRLF. 'Content-disposition: attachment; filename="'.$filename.'"'.CRLF.CRLF; $output .= encode(getFile($filepath)); $output .= MAIL_MIMEPART_CRLF; } $output .= MAIL_MIMEPART_CRLF . '--'.$boundary.MAIL_MIMEPART_CRLF; // $output .= 'Content-type: text/plain; charset="ISO-8859-1"; format=flowed'.CRLF; // $output .= 'Content-transfer-encoding: 7BIT'.CRLF.CRLF; $strHeaders = ''; // Get flat representation of headers foreach ($headers as $name => $value) { $strHeaders .= $name . ': ' . _encodeHeader($value) . CRLF; } return mail($to, $subject, $output, $strHeaders); } function getFile($filename) { $return = ''; if ($fp = fopen($filename, 'rb')) { while (!feof($fp)) { $return .= fread($fp, 1024); } fclose($fp); return $return; } else { return false; } } function encode ($data) { return rtrim(chunk_split(base64_encode($data), 76, MAIL_MIMEPART_CRLF)); } function _encodeHeader($input) { preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $input, $matches); foreach ($matches[1] as $value) { $replacement = preg_replace('/([\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value); $input = str_replace($value, '=?ISO-8859-1?Q?' . $replacement . '?=', $input); } return $input; } ?>