Probléme avec Mailto
bziane2
Messages postés
2
Statut
Membre
-
voyageur59 Messages postés 1123 Statut Membre -
voyageur59 Messages postés 1123 Statut Membre -
Bonjour,
je viens de créer un site en utilisant le langage HTML,par ex dans une page remplir le formulaire et
envoyer
pas de problème de fontionnement du formulaire , mais le problème c'est
qu'il ouvvre "outlock Expres" dans la page web au lieu d'aller directement
la messagerie chez mon hebergeur
Je veux qu'il va directement sans ouvrir l' Outlok Express"
Merci de votre aide
je viens de créer un site en utilisant le langage HTML,par ex dans une page remplir le formulaire et
envoyer
pas de problème de fontionnement du formulaire , mais le problème c'est
qu'il ouvvre "outlock Expres" dans la page web au lieu d'aller directement
la messagerie chez mon hebergeur
Je veux qu'il va directement sans ouvrir l' Outlok Express"
Merci de votre aide
1 réponse
Bonjour,
Deux solution s'offrent pour l'envoi de mail direct: l'hébergeur fournit un script tout fait. Il suffit alors d'aller voir sur le site de l'hébergeur s'il propose ca. Dans ce cas il suffira de suivre les indications.
Si ce n'est pas le cas, il faudra écrire le script.
Pour ça utiliser le PHP.
Voilà a peu près ce que ca donne:
##########################################
class Mail
{
var $sendto= array();
var $from, $msubject;
var $acc= array();
var $abcc= array();
var $aattach= array();
var $priorities= array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
function Mail()
{
$this->autoCheck( true );
}
function autoCheck( $bool )
{
if( $bool )
$this->checkAddress = true;
else
$this->checkAddress = false;
}
function Subject( $subject )
{
$this->msubject = strtr( $subject, "\r\n" , " " );
}
function From( $from )
{
if( ! is_string($from) ) {
exit;
}
$this->from= $from;
}
function To( $to )
{
if( is_array( $to ) )
$this->sendto= $to;
else
$this->sendto[] = $to;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->sendto );
}
function Cc( $cc )
{
if( is_array($cc) )
$this->acc= $cc;
else
$this->acc[]= $cc;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->acc );
}
function Bcc( $bcc )
{
if( is_array($bcc) ) {
$this->abcc = $bcc;
} else {
$this->abcc[]= $bcc;
}
if( $this->checkAddress == true )
$this->CheckAdresses( $this->abcc );
}
function Body( $body )
{
$this->body= $body;
}
function Send()
{
$this->_build_headers();
if( sizeof( $this->aattach > 0 ) ) {
$this->_build_attachement();
$body = $this->fullBody . $this->attachment;
}
// envoie du mail aux destinataires principal
for( $i=0; $i< sizeof($this->sendto); $i++ ) {
$res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);
}
}
function Organization( $org )
{
if( trim( $org != "" ) )
$this->organization= $org;
}
function Priority( $priority )
{
if( ! intval( $priority ) )
return false;
if( ! isset( $this->priorities[$priority-1]) )
return false;
$this->priority= $this->priorities[$priority-1];
return true;
}
function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" )
{
$this->aattach[] = $filename;
$this->actype[] = $filetype;
$this->adispo[] = $disposition;
}
function Get()
{
$this->_build_headers();
if( sizeof( $this->aattach > 0 ) ) {
$this->_build_attachement();
$this->body= $this->body . $this->attachment;
}
$mail = $this->headers;
$mail .= "\n$this->body";
return $mail;
}
function ValidEmail($address)
{
if( ereg( ".*<(.+)>", $address, $regs ) ) {
$address = $regs[1];
}
if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) )
return true;
else
return false;
}
function CheckAdresses( $aad )
{
for($i=0;$i< sizeof( $aad); $i++ ) {
if( ! $this->ValidEmail( $aad[$i]) ) {
exit;
}
}
}
function _build_headers()
{
$this->headers= "From: $this->from\n";
$this->to= implode( ", ", $this->sendto );
if( count($this->acc) > 0 ) {
$this->cc= implode( ", ", $this->acc );
$this->headers .= "CC: $this->cc\n";
}
if( count($this->abcc) > 0 ) {
$this->bcc= implode( ", ", $this->abcc );
$this->headers .= "BCC: $this->bcc\n";
}
if( $this->organization != "" )
$this->headers .= "Organization: $this->organization\n";
if( $this->priority != "" )
$this->headers .= "X-Priority: $this->priority\n";
}
function _build_attachement()
{
$this->boundary= "------------" . md5( uniqid("myboundary") ); // TODO : variable bound
$this->headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$this->boundary\"\n\n";
$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\nContent-Type: text/html; charset=iso-8859-1\nContent-Transfer-Encoding: 8bit\n\n" . $this->body ."\n";
$sep= chr(13) . chr(10);
$ata= array();
$k=0;
// for each attached file, do...
for( $i=0; $i < sizeof( $this->aattach); $i++ ) {
$filename = $this->aattach[$i];
$basename = basename($filename);
$ctype = $this->actype[$i]; // content-type
$disposition = $this->adispo[$i];
if( ! file_exists( $filename) ) {
exit;
}
$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$basename\"\n";
$ata[$k++] = $subhdr;
// non encoded line length
$linesz= filesize( $filename)+1;
$fp= fopen( $filename, 'r' );
$data= base64_encode(fread( $fp, $linesz));
fclose($fp);
$ata[$k++] = chunk_split( $data );
}
$this->attachment= implode($sep, $ata);
}
} // class Mail
$m= new Mail; // create the mail
// ############# contenu du mail ########
$m->From( "$from" );
$m->To( "$destinataire");
$m->Subject( "$objet" );
$m->Body("$texte");
$m->Priority($priority) ;
// #################################
if ($texte!="" && $destinataire!="" && strpos($destinataire, "@")>0 && strpos(strstr($destinataire, "@"),".")>0 )
$m->Send();
##########################################
Un peu long mais il faut ce qu'il faut!
Deux solution s'offrent pour l'envoi de mail direct: l'hébergeur fournit un script tout fait. Il suffit alors d'aller voir sur le site de l'hébergeur s'il propose ca. Dans ce cas il suffira de suivre les indications.
Si ce n'est pas le cas, il faudra écrire le script.
Pour ça utiliser le PHP.
Voilà a peu près ce que ca donne:
##########################################
class Mail
{
var $sendto= array();
var $from, $msubject;
var $acc= array();
var $abcc= array();
var $aattach= array();
var $priorities= array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
function Mail()
{
$this->autoCheck( true );
}
function autoCheck( $bool )
{
if( $bool )
$this->checkAddress = true;
else
$this->checkAddress = false;
}
function Subject( $subject )
{
$this->msubject = strtr( $subject, "\r\n" , " " );
}
function From( $from )
{
if( ! is_string($from) ) {
exit;
}
$this->from= $from;
}
function To( $to )
{
if( is_array( $to ) )
$this->sendto= $to;
else
$this->sendto[] = $to;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->sendto );
}
function Cc( $cc )
{
if( is_array($cc) )
$this->acc= $cc;
else
$this->acc[]= $cc;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->acc );
}
function Bcc( $bcc )
{
if( is_array($bcc) ) {
$this->abcc = $bcc;
} else {
$this->abcc[]= $bcc;
}
if( $this->checkAddress == true )
$this->CheckAdresses( $this->abcc );
}
function Body( $body )
{
$this->body= $body;
}
function Send()
{
$this->_build_headers();
if( sizeof( $this->aattach > 0 ) ) {
$this->_build_attachement();
$body = $this->fullBody . $this->attachment;
}
// envoie du mail aux destinataires principal
for( $i=0; $i< sizeof($this->sendto); $i++ ) {
$res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);
}
}
function Organization( $org )
{
if( trim( $org != "" ) )
$this->organization= $org;
}
function Priority( $priority )
{
if( ! intval( $priority ) )
return false;
if( ! isset( $this->priorities[$priority-1]) )
return false;
$this->priority= $this->priorities[$priority-1];
return true;
}
function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" )
{
$this->aattach[] = $filename;
$this->actype[] = $filetype;
$this->adispo[] = $disposition;
}
function Get()
{
$this->_build_headers();
if( sizeof( $this->aattach > 0 ) ) {
$this->_build_attachement();
$this->body= $this->body . $this->attachment;
}
$mail = $this->headers;
$mail .= "\n$this->body";
return $mail;
}
function ValidEmail($address)
{
if( ereg( ".*<(.+)>", $address, $regs ) ) {
$address = $regs[1];
}
if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) )
return true;
else
return false;
}
function CheckAdresses( $aad )
{
for($i=0;$i< sizeof( $aad); $i++ ) {
if( ! $this->ValidEmail( $aad[$i]) ) {
exit;
}
}
}
function _build_headers()
{
$this->headers= "From: $this->from\n";
$this->to= implode( ", ", $this->sendto );
if( count($this->acc) > 0 ) {
$this->cc= implode( ", ", $this->acc );
$this->headers .= "CC: $this->cc\n";
}
if( count($this->abcc) > 0 ) {
$this->bcc= implode( ", ", $this->abcc );
$this->headers .= "BCC: $this->bcc\n";
}
if( $this->organization != "" )
$this->headers .= "Organization: $this->organization\n";
if( $this->priority != "" )
$this->headers .= "X-Priority: $this->priority\n";
}
function _build_attachement()
{
$this->boundary= "------------" . md5( uniqid("myboundary") ); // TODO : variable bound
$this->headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$this->boundary\"\n\n";
$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\nContent-Type: text/html; charset=iso-8859-1\nContent-Transfer-Encoding: 8bit\n\n" . $this->body ."\n";
$sep= chr(13) . chr(10);
$ata= array();
$k=0;
// for each attached file, do...
for( $i=0; $i < sizeof( $this->aattach); $i++ ) {
$filename = $this->aattach[$i];
$basename = basename($filename);
$ctype = $this->actype[$i]; // content-type
$disposition = $this->adispo[$i];
if( ! file_exists( $filename) ) {
exit;
}
$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$basename\"\n";
$ata[$k++] = $subhdr;
// non encoded line length
$linesz= filesize( $filename)+1;
$fp= fopen( $filename, 'r' );
$data= base64_encode(fread( $fp, $linesz));
fclose($fp);
$ata[$k++] = chunk_split( $data );
}
$this->attachment= implode($sep, $ata);
}
} // class Mail
$m= new Mail; // create the mail
// ############# contenu du mail ########
$m->From( "$from" );
$m->To( "$destinataire");
$m->Subject( "$objet" );
$m->Body("$texte");
$m->Priority($priority) ;
// #################################
if ($texte!="" && $destinataire!="" && strpos($destinataire, "@")>0 && strpos(strstr($destinataire, "@"),".")>0 )
$m->Send();
##########################################
Un peu long mais il faut ce qu'il faut!