Redirection après envoi du formulaire
Fermé
tango95190
Messages postés
3
Date d'inscription
vendredi 26 octobre 2007
Statut
Membre
Dernière intervention
27 octobre 2007
-
26 oct. 2007 à 22:09
Utilisateur anonyme - 27 oct. 2007 à 18:27
Utilisateur anonyme - 27 oct. 2007 à 18:27
A voir également:
- Redirection après envoi du formulaire
- Formulaire de réclamation facebook - Guide
- Civilité sur un formulaire - Forum VB / VBA
- Votre envoi est en cours de transport vers son site de livraison. ✓ - Forum Consommation & Internet
- Récupérer compte outlook sans formulaire - Forum Hotmail / Outlook.com
- Mainlevée de l’envoi international ✓ - Forum Consommation & Internet
5 réponses
Utilisateur anonyme
26 oct. 2007 à 22:50
26 oct. 2007 à 22:50
Bonsoir,
Quelle est la question posée ?
redirection après envoi du formulaire
ai-je bien compris ?
l'utilisateur remplit un formulaire,
on vérifie les infos, on envoit le message et ...
ci après le code utilisé sur a2xsonorisation.org pour une demande de devis
envoi.php
<html>
<head>
<meta http-equiv="Content-Language" content="fr">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1152">
<LINK REL="stylesheet" HREF="monstyle.css" TYPE="text/css">
<title>Contact</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
/*
SCRIPT EDITE SUR L'EDITEUR JAVASCRIPT
http://www.editeurjavascript.com
*/
function VerifForm(formulaire)
{
adresse = formulaire.expediteur.value;
zonemessage = formulaire.message.value;
var place = adresse.indexOf("@",1);
var point = adresse.indexOf(".",place+1);
if (zonemessage == "" ){
alert('zone texte du message invalide!!');
return(false);
}
if ((place > -1)&&(adresse.length >2)&&(point > 1))
{
formulaire.submit();
return(true);
}
else
{
alert('Entrez une adresse e-mail valide!!');
return(false);
}
}
</SCRIPT>
<body background="fond.jpg" >
<!--fichier mail.php-->
<?php
$envoi=$_POST['envoi'];
$destinataire="xxx"."@"."wanadoo.fr";
$expediteur=$_POST['expediteur'];
$sujet="sujet - contact";
$message=$_POST['message'];
if (! isset($envoi)) {
?>
<center><b>Contact </b></center>
<form name="formulaire" method="post" action="mail.php" onSubmit="return(VerifForm(this));">
<table border=0 width=80% cellspacing=3 cellpadding=3 align='center'><tr>
<td> Destinataire </td>
<td><input readonly type=text name='destinataire' size=30 value='xxx'></td>
</tr><tr>
<td> Expéditeur </td>
<td><input type=text name='expediteur' size=30 value=''> (entrez votre adresse électronique).</td>
</tr><tr>
<td> Sujet </td>
<td><input readonly type=text name='sujet' size=30 value='A2x Sonorisation - contact'></td>
</tr><tr>
<td> Votre message </td>
<td><textarea rows=10 cols=50 name='message' value='Voici mon message\n'></textarea></td>
</tr><tr>
<td>Validation : </td>
<td><input type='submit' name='envoi' value='Envoyer' ></td>
</tr>
<tr> <td colspan='2'>Aucune des informations entrées ici n'est conservée dans une base.
</td></tr>
</table>
</form>
<?php
}
else {
/* pour neutraliser les \ ajoutés à la transmission devant les ' et les " */
$message=stripslashes($message);
$sujet=stripslashes($sujet);
$entete="From: $expediteur\r\nReply-To: $expediteur\r\nX-Mailer: PHP/";
/* expédition et compte-rendu */
$ok=mail($destinataire, $sujet,$message,$entete);
if ($ok){
echo "Envoi du message à xxx réussi !";
echo "<br><input type='button' value=' Terminer ' onclick='javascript:window.close()'>";
}
else {
echo "L'envoi a échoué ..";
echo "<br><input type='button' value=' Terminer ' onclick='javascript:window.close()'>";
}
}
?>
----------------------------------------------------
envoi.php
<?
$adressemail = $_GET["adresse_email"];
$zone = $_GET["zone"];
$nompre = $_GET["nompre"];
echo "<body background='fond.jpg'>";
echo "<font color='blue'>";
echo "xxx vous remercie de votre confiance et met tout en oeuvre pour ";
echo "satisfaire votre demande dans les plus brefs délais</font>";
//---------------------------------
$message= "";
$message .= "<html>";
$message .= "<meta http-equiv='Content-Type' content='text/html; charset=windows-1152'>";
$message .= "<body background='fond.jpg' >";
$message .= "<font color='blue'><br><br><b>Contact</b></font>";
$message .= "<br>";
$message .= "<hr size=2 align=center color='#0000FF'>";
$message .= "<table>";
$message .= "<tr>";
$message .= "<td width=50%>";
$message .= "E-mail : $adressemail<br>";
$message .= "</tr>";
$message .= "</table>";
$message .= "<hr size=2 align=center color='#0000FF'>";
$message .= "$zone<br>";
$message .= "</td></tr></table>";
$message .= "<hr size=2 width='100%' align=center color='#0000FF'>";
$message .= "</html> ";
//-------------------------------
include('class.mail.php');
$mail = new simplemail;
$mail -> addrecipient(xxx@ihotmail.fr','qqq');
$mail -> addfrom('.$adressemail.','xxx');
$mail -> addsubject(' - Contact');
// le message text
//$mail -> text = 'Demande de devis';
// le message format html
$mail -> html = "$message";
if ( $mail -> sendmail() ) { echo "<br>Votre message a été envoyé"; } else { echo "<br>erreur dans l'envoi du message"; echo $mail->error_log; }
echo "<br>";
echo "<input type='button' value=' Terminer ' onclick='javascript:window.close()'>";
---------------------------------
class.mail.php
<?php
class simplemail {
var $recipientlist;
var $subject;
var $hfrom;
var $hbcc;
var $hcc;
var $Xsender;
var $ErrorsTo;
var $XMailer = 'PHP';
var $XPriority = 3;
var $set_mode='php';
var $text;
var $html;
var $attachement;
var $htmlattachement;
var $recipient;
var $body;
var $headers;
var $error_log;
var $connect;
var $default_charset = 'iso-8859-1';
var $B1B = "----=_001";
var $B2B = "----=_002";
var $B3B = "----=_003";
function simplemail() {
$this -> attachement = array();
$this -> htmlattachement = array();
}
function checkaddress($address) {
if ( preg_match('`(:alnum:([-_.]?:alnum:)*@:alnum:([-_.]?:alnum:)*\.([a-z]{2,4}))`', $address) ) {
return TRUE;
} else {
$this->error_log("l'adresse $address est invalide"); return FALSE;
}
}
function checkname($name) {
if ( preg_match("`[0-9a-zA-Z\.\-_ ]*`" , $name ) ) {
return TRUE;
} else {
$this->error_log(" le pseudo $name est invalide\n"); return FALSE;
}
}
function makenameplusaddress($address,$name) {
if ( !$this->checkaddress($address) ) return FALSE;
if ( !$this->checkname($name) ) return FALSE;
if ( empty($name) ) { return $address; }
else { $tmp=$name." <".$address.">"; return $tmp; }
}
function addrecipient($newrecipient,$name='') {
$tmp=$this->makenameplusaddress($newrecipient,$name);
if ( !$tmp ) { $this->error_log(" To: error"); return FALSE; }
$this->recipientlist[] = array( 'mail'=>$newrecipient, 'nameplusmail' => $tmp );
return TRUE;
}
function addbcc($bcc,$name='') {
$tmp=$this->makenameplusaddress($bcc,$name);
if ( !$tmp ) { $this->error_log(" Bcc: error"); return FALSE; }
if ( !empty($this->hbcc)) $this->hbcc.= ",";
$this->hbcc.= $tmp;
return TRUE;
}
function addcc($cc,$name='') {
$tmp=$this->makenameplusaddress($cc,$name);
if ( !$tmp ) { $this->error_log(" Cc: error\n"); return FALSE; }
if (!empty($this->hcc)) $this->hcc.= ",";
$this->hcc.= $tmp;
return TRUE;
}
function addsubject($subject) {
if (!empty($subject)) $this->subject = $subject;
}
function addfrom($from,$name='') {
$tmp=$this->makenameplusaddress($from,$name);
if ( !$tmp ) { $this->error_log(" From: error"); return FALSE; }
$this->hfrom = $tmp;
return TRUE;
}
function addreturnpath($return) {
$tmp=$this->makenameplusaddress($return,'');
if ( !$tmp ) { $this->error_log("Return-Path: error"); return FALSE; }
$this->returnpath = $return;
return TRUE;
}
function addreplyto($replyto) {
$tmp=$this->makenameplusaddress($replyto,'');
if ( !$tmp ) { $this->error_log(" Reply-To: error"); return FALSE; }
$this->returnpath = $tmp;
return TRUE;
}
// les attachements
function addattachement($filename) {
array_push ( $this -> attachement , array ( 'filename'=> $filename ) );
}
// les attachements html
function addhtmlattachement($filename,$cid='',$contenttype='') {
array_push ( $this -> htmlattachement ,
array ( 'filename'=>$filename ,
'cid'=>$cid ,
'contenttype'=>$contenttype )
);
}
function writeattachement(&$attachement,$B) {
$message = '';
if ( !empty($attachement) ) {
foreach($attachement as $AttmFile){
$patharray = explode ("/", $AttmFile['filename']);
$FileName = $patharray[count($patharray)-1];
$message .= "\n--".$B."\n";
if (!empty($AttmFile['cid'])) {
$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-ID: <{$AttmFile['cid']}>\n";
$message .= "Content-Disposition: inline;\n filename=\"".$FileName."\"\n\n";
} else {
$message .= "Content-Type: application/octetstream;\n name=\"".$FileName."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n";
}
$fd=fopen ($AttmFile['filename'], "rb");
$FileContent=fread($fd,filesize($AttmFile['filename']));
fclose ($fd);
$FileContent = chunk_split(base64_encode($FileContent));
$message .= $FileContent;
$message .= "\n\n";
}
$message .= "\n--".$B."--\n";
}
return $message;
}
function BodyLineWrap($Value) {
return wordwrap($Value, 78, "\n ");
}
function makebody() {
$message='';
if ( !$this->html && $this->text && !empty($this->attachement) ) {
//Messages start with text/html alternatives in OB
$message ="This is a multi-part message in MIME format.\n";
$message.="\n--".$this->B1B."\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$message.=$this->BodyLineWrap($this->text)."\n\n";
$message.=$this->writeattachement($this->attachement,$this->B1B);
}
elseif ( !$this->html && $this->text && empty($this->attachement) ) {
// plaintext goes here
$message.=$this->BodyLineWrap($this->text)."\n\n";
}
elseif ( $this->html ) {
//Messages start with text/html alternatives in OB
$message ="This is a multi-part message in MIME format.\n";
$message.="\n--".$this->B1B."\n";
$message.="Content-Type: multipart/related;\n\t boundary=\"".$this->B2B."\"\n\n";
//plaintext section
$message.="\n--".$this->B2B."\n";
$message.="Content-Type: multipart/alternative;\n\t boundary=\"".$this->B3B."\"\n\n";
//plaintext section
$message.="\n--".$this->B3B."\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$message.=$this->BodyLineWrap($this->text)."\n\n";
// html section
$message.="\n--".$this->B3B."\n";
$message.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$message.=chunk_split(base64_encode($this->html))."\n\n";
// end of text
$message.="\n--".$this->B3B."--\n";
// attachments html
if (empty($this->htmlattachement)) {
$message.="\n--".$this->B2B."--\n";
} else {
$message.=$this->writeattachement( $this->htmlattachement,$this->B2B);
}
// attachments
if (empty($this->attachement)) {
$message.="\n--".$this->B1B."--\n";
} else {
$message.=$this->writeattachement($this->attachement,$this->B1B);
}
}
$this->body = $message;
return $message;
}
// Mail Headers Methods
function MakeHeaderField($Field,$Value) {
return wordwrap($Field.": ".$Value, 78, "\n ")."\r\n";
}
function AddField2Header($Field,$Value) {
$this->headers .= $this->MakeHeaderField($Field,$Value);
}
function makeheader() {
$this->headers = '';
if ( empty($this->recipientlist) ) { $this->error_log("destinataire manquant"); return FALSE; }
// else { $this->AddField2Header("To",$this->recipient); }
if ( empty($this->subject) ) {
$this->error_log("sujet manquant");
return FALSE;
} else {
if ($this->set_mode!='php' ) {
$this->AddField2Header("Subject", $this->subject);
}
}
# Date: Mon, 03 Nov 2003 20:48:06 +0100
$this->AddField2Header("Date", date ('r'));
if ( !empty($this->Xsender) ) { $this->AddField2Header("X-Sender",$this->Xsender); }
else { $this->AddField2Header("X-Sender",$this->hfrom); }
if ( !empty($this->ErrorsTo) ) { $this->AddField2Header("Errors-To",$this->ErrorsTo); }
else { $this->AddField2Header("Errors-To",$this->hfrom); }
if ( !empty($this->XMailer) ) $this->AddField2Header("X-Mailer",$this->XMailer);
if ( !empty($this->XPriority) ) $this->AddField2Header("X-Priority",$this->XPriority);
if ( !empty($this->hfrom) ) $this->AddField2Header("From",$this->hfrom);
if ( !empty($this->returnpath) ) $this->AddField2Header("Return-Path",$this->returnpath);
if ( !empty($this->replyto) ) $this->AddField2Header("Reply-To",$this->replyto);
$this->headers .="MIME-Version: 1.0\r\n";
if ( !$this->html && $this->text && !empty($this->attachement) ) {
$this->headers .= "Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
} elseif ( !$this->html && $this->text && empty($this->attachement) ) {
$this->headers .="Content-Type: text/plain; charset=us-ascii; format=flowed\r\n";
$this->headers .="Content-Transfer-Encoding: 7bit\r\n";
} elseif ( $this->html ) {
if ( !$this->text ) { $this->text="HTML only!"; }
$this->headers .="Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
}
if ( !empty($this->hcc) ) $this->AddField2Header("Cc",$this->hcc);
if ( !empty($this->hbcc) ) $this->AddField2Header("Bcc",$this->hbcc);
return $this->headers;
}
function sendmail() {
$this->makebody();
$this->makeheader();
switch($this->set_mode) {
case 'php' : $this->phpmail(); break;
case 'socket': $this->socketmailloop(); break;
}
return TRUE;
}
// Mail send by PHPmail
function phpmail() {
while ( list($key, $to) = each($this->recipientlist) ) {
$this->recipient = $to['mail'];
if ( mail($to['mail'], $this->subject, $this->body, $this->makeheader() ) ) {
$this->error_log("envoie vers {$to['nameplusmail']} réussi");
} else {
$this->error_log("envoie vers {$to['nameplusmail']} echoué");
}
}
return TRUE;
}
// Socket Function
function SocketStart() {
if (!$this->connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30)) {
$this->error_log("Could not talk to the sendmail server!"); return FALSE;
};
return fgets($this->connect, 1024);
}
function SocketStop() {
fclose($this->connect);
return TRUE;
}
function SocketSend($in,$wait='') {
fputs($this->connect, $in, strlen($in));
echo "-"; flush();
if(empty($wait)) {
$rcv = fgets($this->connect, 1024);
return $rcv;
}
return TRUE;
}
// Mail Socket
function socketmailstart() {
$this->SocketStart();
if (!isset($_SERVER['SERVER_NAME']) || empty($_SERVER['SERVER_NAME'])) { $serv = 'unknown'; }
else { $serv = $_SERVER['SERVER_NAME']; }
$this->SocketSend("HELO $serv\r\n");
}
function socketmailsend($to) {
$this->recipient = $to;
$this->error_log("Socket vers $to");
$this->SocketSend( "MAIL FROM:{$this->hfrom}\r\n" );
$this->SocketSend( "RCPT TO:$to\r\n" );
$this->SocketSend( "DATA\r\n" );
$this->SocketSend( $this->CleanMailDataString($this->headers)."\r\n", 'NOWAIT' );
$this->SocketSend( $this->CleanMailDataString($this->body)."\r\n", 'NOWAIT' );
$this->SocketSend( ".\r\n" );
$this->SocketSend( "RSET\r\n" );
$this->error_log("Fin de l'envoi vers $to");
return TRUE;
}
function socketmailstop() {
$this->SocketSend("QUIT\r\n");
$this->SocketStop();
return TRUE;
}
function socketmailloop() {
$this->socketmailstart();
while ( list($key, $to) = each($this->recipientlist)) {
$this->recipient = $to['mail'];
$this->makeheader();
$this->socketmailsend($to['mail']);
}
$this->socketmailstop();
}
// Misc.
function error_log($msg='') {
if(!empty($msg)) {
$this->error_log .= $msg . "\r\n--\r\n";
return TRUE;
}
return " --- Error Log --- \r\n\r\n".$this->error_log;
}
function CleanMailDataString($data) {
$data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data);
$data = preg_replace("/\n\n/", "\n\r\n", $data);
$data = preg_replace("/\n\./", "\n..", $data);
return $data;
}
}
?>
Quelle est la question posée ?
redirection après envoi du formulaire
ai-je bien compris ?
l'utilisateur remplit un formulaire,
on vérifie les infos, on envoit le message et ...
ci après le code utilisé sur a2xsonorisation.org pour une demande de devis
envoi.php
<html>
<head>
<meta http-equiv="Content-Language" content="fr">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1152">
<LINK REL="stylesheet" HREF="monstyle.css" TYPE="text/css">
<title>Contact</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
/*
SCRIPT EDITE SUR L'EDITEUR JAVASCRIPT
http://www.editeurjavascript.com
*/
function VerifForm(formulaire)
{
adresse = formulaire.expediteur.value;
zonemessage = formulaire.message.value;
var place = adresse.indexOf("@",1);
var point = adresse.indexOf(".",place+1);
if (zonemessage == "" ){
alert('zone texte du message invalide!!');
return(false);
}
if ((place > -1)&&(adresse.length >2)&&(point > 1))
{
formulaire.submit();
return(true);
}
else
{
alert('Entrez une adresse e-mail valide!!');
return(false);
}
}
</SCRIPT>
<body background="fond.jpg" >
<!--fichier mail.php-->
<?php
$envoi=$_POST['envoi'];
$destinataire="xxx"."@"."wanadoo.fr";
$expediteur=$_POST['expediteur'];
$sujet="sujet - contact";
$message=$_POST['message'];
if (! isset($envoi)) {
?>
<center><b>Contact </b></center>
<form name="formulaire" method="post" action="mail.php" onSubmit="return(VerifForm(this));">
<table border=0 width=80% cellspacing=3 cellpadding=3 align='center'><tr>
<td> Destinataire </td>
<td><input readonly type=text name='destinataire' size=30 value='xxx'></td>
</tr><tr>
<td> Expéditeur </td>
<td><input type=text name='expediteur' size=30 value=''> (entrez votre adresse électronique).</td>
</tr><tr>
<td> Sujet </td>
<td><input readonly type=text name='sujet' size=30 value='A2x Sonorisation - contact'></td>
</tr><tr>
<td> Votre message </td>
<td><textarea rows=10 cols=50 name='message' value='Voici mon message\n'></textarea></td>
</tr><tr>
<td>Validation : </td>
<td><input type='submit' name='envoi' value='Envoyer' ></td>
</tr>
<tr> <td colspan='2'>Aucune des informations entrées ici n'est conservée dans une base.
</td></tr>
</table>
</form>
<?php
}
else {
/* pour neutraliser les \ ajoutés à la transmission devant les ' et les " */
$message=stripslashes($message);
$sujet=stripslashes($sujet);
$entete="From: $expediteur\r\nReply-To: $expediteur\r\nX-Mailer: PHP/";
/* expédition et compte-rendu */
$ok=mail($destinataire, $sujet,$message,$entete);
if ($ok){
echo "Envoi du message à xxx réussi !";
echo "<br><input type='button' value=' Terminer ' onclick='javascript:window.close()'>";
}
else {
echo "L'envoi a échoué ..";
echo "<br><input type='button' value=' Terminer ' onclick='javascript:window.close()'>";
}
}
?>
----------------------------------------------------
envoi.php
<?
$adressemail = $_GET["adresse_email"];
$zone = $_GET["zone"];
$nompre = $_GET["nompre"];
echo "<body background='fond.jpg'>";
echo "<font color='blue'>";
echo "xxx vous remercie de votre confiance et met tout en oeuvre pour ";
echo "satisfaire votre demande dans les plus brefs délais</font>";
//---------------------------------
$message= "";
$message .= "<html>";
$message .= "<meta http-equiv='Content-Type' content='text/html; charset=windows-1152'>";
$message .= "<body background='fond.jpg' >";
$message .= "<font color='blue'><br><br><b>Contact</b></font>";
$message .= "<br>";
$message .= "<hr size=2 align=center color='#0000FF'>";
$message .= "<table>";
$message .= "<tr>";
$message .= "<td width=50%>";
$message .= "E-mail : $adressemail<br>";
$message .= "</tr>";
$message .= "</table>";
$message .= "<hr size=2 align=center color='#0000FF'>";
$message .= "$zone<br>";
$message .= "</td></tr></table>";
$message .= "<hr size=2 width='100%' align=center color='#0000FF'>";
$message .= "</html> ";
//-------------------------------
include('class.mail.php');
$mail = new simplemail;
$mail -> addrecipient(xxx@ihotmail.fr','qqq');
$mail -> addfrom('.$adressemail.','xxx');
$mail -> addsubject(' - Contact');
// le message text
//$mail -> text = 'Demande de devis';
// le message format html
$mail -> html = "$message";
if ( $mail -> sendmail() ) { echo "<br>Votre message a été envoyé"; } else { echo "<br>erreur dans l'envoi du message"; echo $mail->error_log; }
echo "<br>";
echo "<input type='button' value=' Terminer ' onclick='javascript:window.close()'>";
---------------------------------
class.mail.php
<?php
class simplemail {
var $recipientlist;
var $subject;
var $hfrom;
var $hbcc;
var $hcc;
var $Xsender;
var $ErrorsTo;
var $XMailer = 'PHP';
var $XPriority = 3;
var $set_mode='php';
var $text;
var $html;
var $attachement;
var $htmlattachement;
var $recipient;
var $body;
var $headers;
var $error_log;
var $connect;
var $default_charset = 'iso-8859-1';
var $B1B = "----=_001";
var $B2B = "----=_002";
var $B3B = "----=_003";
function simplemail() {
$this -> attachement = array();
$this -> htmlattachement = array();
}
function checkaddress($address) {
if ( preg_match('`(:alnum:([-_.]?:alnum:)*@:alnum:([-_.]?:alnum:)*\.([a-z]{2,4}))`', $address) ) {
return TRUE;
} else {
$this->error_log("l'adresse $address est invalide"); return FALSE;
}
}
function checkname($name) {
if ( preg_match("`[0-9a-zA-Z\.\-_ ]*`" , $name ) ) {
return TRUE;
} else {
$this->error_log(" le pseudo $name est invalide\n"); return FALSE;
}
}
function makenameplusaddress($address,$name) {
if ( !$this->checkaddress($address) ) return FALSE;
if ( !$this->checkname($name) ) return FALSE;
if ( empty($name) ) { return $address; }
else { $tmp=$name." <".$address.">"; return $tmp; }
}
function addrecipient($newrecipient,$name='') {
$tmp=$this->makenameplusaddress($newrecipient,$name);
if ( !$tmp ) { $this->error_log(" To: error"); return FALSE; }
$this->recipientlist[] = array( 'mail'=>$newrecipient, 'nameplusmail' => $tmp );
return TRUE;
}
function addbcc($bcc,$name='') {
$tmp=$this->makenameplusaddress($bcc,$name);
if ( !$tmp ) { $this->error_log(" Bcc: error"); return FALSE; }
if ( !empty($this->hbcc)) $this->hbcc.= ",";
$this->hbcc.= $tmp;
return TRUE;
}
function addcc($cc,$name='') {
$tmp=$this->makenameplusaddress($cc,$name);
if ( !$tmp ) { $this->error_log(" Cc: error\n"); return FALSE; }
if (!empty($this->hcc)) $this->hcc.= ",";
$this->hcc.= $tmp;
return TRUE;
}
function addsubject($subject) {
if (!empty($subject)) $this->subject = $subject;
}
function addfrom($from,$name='') {
$tmp=$this->makenameplusaddress($from,$name);
if ( !$tmp ) { $this->error_log(" From: error"); return FALSE; }
$this->hfrom = $tmp;
return TRUE;
}
function addreturnpath($return) {
$tmp=$this->makenameplusaddress($return,'');
if ( !$tmp ) { $this->error_log("Return-Path: error"); return FALSE; }
$this->returnpath = $return;
return TRUE;
}
function addreplyto($replyto) {
$tmp=$this->makenameplusaddress($replyto,'');
if ( !$tmp ) { $this->error_log(" Reply-To: error"); return FALSE; }
$this->returnpath = $tmp;
return TRUE;
}
// les attachements
function addattachement($filename) {
array_push ( $this -> attachement , array ( 'filename'=> $filename ) );
}
// les attachements html
function addhtmlattachement($filename,$cid='',$contenttype='') {
array_push ( $this -> htmlattachement ,
array ( 'filename'=>$filename ,
'cid'=>$cid ,
'contenttype'=>$contenttype )
);
}
function writeattachement(&$attachement,$B) {
$message = '';
if ( !empty($attachement) ) {
foreach($attachement as $AttmFile){
$patharray = explode ("/", $AttmFile['filename']);
$FileName = $patharray[count($patharray)-1];
$message .= "\n--".$B."\n";
if (!empty($AttmFile['cid'])) {
$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-ID: <{$AttmFile['cid']}>\n";
$message .= "Content-Disposition: inline;\n filename=\"".$FileName."\"\n\n";
} else {
$message .= "Content-Type: application/octetstream;\n name=\"".$FileName."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n";
}
$fd=fopen ($AttmFile['filename'], "rb");
$FileContent=fread($fd,filesize($AttmFile['filename']));
fclose ($fd);
$FileContent = chunk_split(base64_encode($FileContent));
$message .= $FileContent;
$message .= "\n\n";
}
$message .= "\n--".$B."--\n";
}
return $message;
}
function BodyLineWrap($Value) {
return wordwrap($Value, 78, "\n ");
}
function makebody() {
$message='';
if ( !$this->html && $this->text && !empty($this->attachement) ) {
//Messages start with text/html alternatives in OB
$message ="This is a multi-part message in MIME format.\n";
$message.="\n--".$this->B1B."\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$message.=$this->BodyLineWrap($this->text)."\n\n";
$message.=$this->writeattachement($this->attachement,$this->B1B);
}
elseif ( !$this->html && $this->text && empty($this->attachement) ) {
// plaintext goes here
$message.=$this->BodyLineWrap($this->text)."\n\n";
}
elseif ( $this->html ) {
//Messages start with text/html alternatives in OB
$message ="This is a multi-part message in MIME format.\n";
$message.="\n--".$this->B1B."\n";
$message.="Content-Type: multipart/related;\n\t boundary=\"".$this->B2B."\"\n\n";
//plaintext section
$message.="\n--".$this->B2B."\n";
$message.="Content-Type: multipart/alternative;\n\t boundary=\"".$this->B3B."\"\n\n";
//plaintext section
$message.="\n--".$this->B3B."\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$message.=$this->BodyLineWrap($this->text)."\n\n";
// html section
$message.="\n--".$this->B3B."\n";
$message.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$message.=chunk_split(base64_encode($this->html))."\n\n";
// end of text
$message.="\n--".$this->B3B."--\n";
// attachments html
if (empty($this->htmlattachement)) {
$message.="\n--".$this->B2B."--\n";
} else {
$message.=$this->writeattachement( $this->htmlattachement,$this->B2B);
}
// attachments
if (empty($this->attachement)) {
$message.="\n--".$this->B1B."--\n";
} else {
$message.=$this->writeattachement($this->attachement,$this->B1B);
}
}
$this->body = $message;
return $message;
}
// Mail Headers Methods
function MakeHeaderField($Field,$Value) {
return wordwrap($Field.": ".$Value, 78, "\n ")."\r\n";
}
function AddField2Header($Field,$Value) {
$this->headers .= $this->MakeHeaderField($Field,$Value);
}
function makeheader() {
$this->headers = '';
if ( empty($this->recipientlist) ) { $this->error_log("destinataire manquant"); return FALSE; }
// else { $this->AddField2Header("To",$this->recipient); }
if ( empty($this->subject) ) {
$this->error_log("sujet manquant");
return FALSE;
} else {
if ($this->set_mode!='php' ) {
$this->AddField2Header("Subject", $this->subject);
}
}
# Date: Mon, 03 Nov 2003 20:48:06 +0100
$this->AddField2Header("Date", date ('r'));
if ( !empty($this->Xsender) ) { $this->AddField2Header("X-Sender",$this->Xsender); }
else { $this->AddField2Header("X-Sender",$this->hfrom); }
if ( !empty($this->ErrorsTo) ) { $this->AddField2Header("Errors-To",$this->ErrorsTo); }
else { $this->AddField2Header("Errors-To",$this->hfrom); }
if ( !empty($this->XMailer) ) $this->AddField2Header("X-Mailer",$this->XMailer);
if ( !empty($this->XPriority) ) $this->AddField2Header("X-Priority",$this->XPriority);
if ( !empty($this->hfrom) ) $this->AddField2Header("From",$this->hfrom);
if ( !empty($this->returnpath) ) $this->AddField2Header("Return-Path",$this->returnpath);
if ( !empty($this->replyto) ) $this->AddField2Header("Reply-To",$this->replyto);
$this->headers .="MIME-Version: 1.0\r\n";
if ( !$this->html && $this->text && !empty($this->attachement) ) {
$this->headers .= "Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
} elseif ( !$this->html && $this->text && empty($this->attachement) ) {
$this->headers .="Content-Type: text/plain; charset=us-ascii; format=flowed\r\n";
$this->headers .="Content-Transfer-Encoding: 7bit\r\n";
} elseif ( $this->html ) {
if ( !$this->text ) { $this->text="HTML only!"; }
$this->headers .="Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
}
if ( !empty($this->hcc) ) $this->AddField2Header("Cc",$this->hcc);
if ( !empty($this->hbcc) ) $this->AddField2Header("Bcc",$this->hbcc);
return $this->headers;
}
function sendmail() {
$this->makebody();
$this->makeheader();
switch($this->set_mode) {
case 'php' : $this->phpmail(); break;
case 'socket': $this->socketmailloop(); break;
}
return TRUE;
}
// Mail send by PHPmail
function phpmail() {
while ( list($key, $to) = each($this->recipientlist) ) {
$this->recipient = $to['mail'];
if ( mail($to['mail'], $this->subject, $this->body, $this->makeheader() ) ) {
$this->error_log("envoie vers {$to['nameplusmail']} réussi");
} else {
$this->error_log("envoie vers {$to['nameplusmail']} echoué");
}
}
return TRUE;
}
// Socket Function
function SocketStart() {
if (!$this->connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30)) {
$this->error_log("Could not talk to the sendmail server!"); return FALSE;
};
return fgets($this->connect, 1024);
}
function SocketStop() {
fclose($this->connect);
return TRUE;
}
function SocketSend($in,$wait='') {
fputs($this->connect, $in, strlen($in));
echo "-"; flush();
if(empty($wait)) {
$rcv = fgets($this->connect, 1024);
return $rcv;
}
return TRUE;
}
// Mail Socket
function socketmailstart() {
$this->SocketStart();
if (!isset($_SERVER['SERVER_NAME']) || empty($_SERVER['SERVER_NAME'])) { $serv = 'unknown'; }
else { $serv = $_SERVER['SERVER_NAME']; }
$this->SocketSend("HELO $serv\r\n");
}
function socketmailsend($to) {
$this->recipient = $to;
$this->error_log("Socket vers $to");
$this->SocketSend( "MAIL FROM:{$this->hfrom}\r\n" );
$this->SocketSend( "RCPT TO:$to\r\n" );
$this->SocketSend( "DATA\r\n" );
$this->SocketSend( $this->CleanMailDataString($this->headers)."\r\n", 'NOWAIT' );
$this->SocketSend( $this->CleanMailDataString($this->body)."\r\n", 'NOWAIT' );
$this->SocketSend( ".\r\n" );
$this->SocketSend( "RSET\r\n" );
$this->error_log("Fin de l'envoi vers $to");
return TRUE;
}
function socketmailstop() {
$this->SocketSend("QUIT\r\n");
$this->SocketStop();
return TRUE;
}
function socketmailloop() {
$this->socketmailstart();
while ( list($key, $to) = each($this->recipientlist)) {
$this->recipient = $to['mail'];
$this->makeheader();
$this->socketmailsend($to['mail']);
}
$this->socketmailstop();
}
// Misc.
function error_log($msg='') {
if(!empty($msg)) {
$this->error_log .= $msg . "\r\n--\r\n";
return TRUE;
}
return " --- Error Log --- \r\n\r\n".$this->error_log;
}
function CleanMailDataString($data) {
$data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data);
$data = preg_replace("/\n\n/", "\n\r\n", $data);
$data = preg_replace("/\n\./", "\n..", $data);
return $data;
}
}
?>
tango95190
Messages postés
3
Date d'inscription
vendredi 26 octobre 2007
Statut
Membre
Dernière intervention
27 octobre 2007
27 oct. 2007 à 00:11
27 oct. 2007 à 00:11
Bonjour ,
Pouvez vous me dire si je peux faire une redirection après que le visiteur est envoyer le mail a mon adresse email via le formulaire , en incluant une séquence dans mon formulaire
Pouvez vous me dire si je peux faire une redirection après que le visiteur est envoyer le mail a mon adresse email via le formulaire , en incluant une séquence dans mon formulaire
Utilisateur anonyme
27 oct. 2007 à 14:49
27 oct. 2007 à 14:49
Bonjour,
sur la page qui dit votre mail a bien été envoyé on peut mettre :
<script language="javascript">
document.location="url.htm";
</script>
sur la page qui dit votre mail a bien été envoyé on peut mettre :
<script language="javascript">
document.location="url.htm";
</script>
tango95190
Messages postés
3
Date d'inscription
vendredi 26 octobre 2007
Statut
Membre
Dernière intervention
27 octobre 2007
27 oct. 2007 à 16:52
27 oct. 2007 à 16:52
Bonjour,
jes que un fichier contacT regarder le ses le code du début je peux intégrer sa dessus ou pas , Met ou ????
jes que un fichier contacT regarder le ses le code du début je peux intégrer sa dessus ou pas , Met ou ????
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Utilisateur anonyme
27 oct. 2007 à 18:27
27 oct. 2007 à 18:27
ce script s'executera dans la séquence, là où il aura été mis.