.01
.02
.03
.04
.05
.06
.07
.08
.09
.10
.11
.12
.13
.14
.15
.16
.17
.18
.19
.20
.21
.22
.23
.24
.25
.26
.27
.28
.29
.30
.31
.32
.33
.34
.35
.36
.37
.38
.39
.40
.41
.42
.43
.44
.45
.46
.47
.48
.49
.50
.51
.52
.53
.54
.55
.56
.57
.58
.59
.60
.61
.62
.63
.64
.65
.66
.67
.68
.69
.70
.71
.72
.73
.74
.75
.76
.77
.78
.79
.80
.81
.82
.83
.84
.85
.86
.87
.88
.89
.90
.91
.92
.93
.94
.95
.96
.97
.98
.99
.100
.101
.102
.103
.104
.105
.106
.107
.108
.109
.110
.111
.112
.113
.114
.115
.116
.117
.118
|
|
<?php
/******************************************************************************/
/* */
/* __ ____ */
/* ___ / / ___ / __/__ __ _____________ ___ */
/* / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-< */
/* / .__/_//_/ .__/___/\___/\_,_/_/ \__/\__/___/ */
/* /_/ /_/ */
/* */
/* */
/******************************************************************************/
/* */
/* Titre : Envoyer un mail type MINE en HTML */
/* */
/* URL : http://www.phpsources.org/scripts427-PHP.htm */
/* Auteur : Mathias */
/* Date édition : 16 Juil 2008 */
/* */
/******************************************************************************/
// include MIME mailer class
class Mailer{
var $sender;
var $recipient;
var $subject;
var $headers=array();
function Mailer($sender,$recipient,$subject,$message){
// validate incoming parameters
if(!preg_match("/^.+@.+$/",$sender)){
trigger_error('Invalid value for email sender.',E_USER_ERROR);
}
if(!preg_match("/^.+@.+$/",$recipient)){
trigger_error('Invalid value for email recipient.',E_USER_ERROR);
}
if(!$subject||strlen($subject)>255){
trigger_error('Invalid length for email subject.',E_USER_ERROR);
}
if(!$message){
trigger_error('Invalid value for email message.',E_USER_ERROR);
}
$this->sender=$sender;
$this->recipient=$recipient;
$this->subject=$subject;
$this->message=$message;
// define some default MIME headers
$this->headers['MIME-Version']='1.0';
$this->headers['Content-Type']='multipart/mixed;boundary="MIME_BOUNDRY"';
$this->headers['From']='<'.$this->sender.'>';
$this->headers['Return-Path']='<'.$this->sender.'>';
$this->headers['Reply-To']=$this->sender;
$this->headers['X-Mailer']='PHP 4/5';
$this->headers['X-Sender']=$this->sender;
$this->headers['X-Priority']='3';
}
// create text part of the message
function buildTextPart(){
$mine = "--MIME_BOUNDRYnContent-Type: text/plain;";
$mine.= " charset=iso-8859-1nContent-Transfer-Encoding:";
$mine.= " quoted-printablennn".$this->message."\n\n";
return $mine;
}
// create message MIME headers
function buildHeaders(){
foreach($this->headers as $name=>$value){
$headers[]=$name.': '.$value;
}
return implode("\n",$headers)."\nThis is a multi-part message in MIME format.\n";
}
// add new MIME header
function addHeader($name,$value){
$this->headers[$name]=$value;
}
// send email
function send(){
$to=$this->recipient;
$subject=$this->subject;
$headers=$this->buildHeaders();
$message=$this->buildTextPart()."--MIME_BOUNDRY--\n";
if(!mail($to,$subject,$message,$headers)){
trigger_error('Error sending email.',E_USER_ERROR);
}
return true;
}
}
// create a new instance of the 'Mailer' class
$mailer=&new Mailer('nom@domain.com','mynom@domain.com','Test','hello');
// send MIME email message
if($mailer->send()){
echo 'Meesage envoyé avec succés.';
} ?>
|