Formulaire / php

Utilisateur anonyme -  
 Utilisateur anonyme -
Bonjour,

J'ai cherché partout sur internet, visiter des dizaines de sites, mais je suis totalement perdu
J'ai un script me servant de formulaire: formulaire.php
Et une page formmail.php censée m'envoyer le mail avec le contenu du formulaire

Qd j'appuie sur envoyer, j'arrive bien sur la page prévue mais je ne reçois rien

Voilà le forumulaire.php :
[code]<form method=POST action=formmail.php >
<input type=hidden name=subject value=formmail>

<br/>

<P> <FONT SIZE=4 COLOR="grey"><b>Formulaire de commande</b></FONT> </P>

<br/>
<p class="MsoNormal"><input name="Sexe" value="M" checked="checked" type="radio">Mr <input name="Sexe" value="F" type="radio">Mme <input name="Sexe" value="D" type="radio">Mlle</p>

<p class="MsoNormal"><b>Votre Nom</b>
<br><input name="Nom" type="text"></p>

<p class="MsoNormal"><b>Votre Prénom</b>
<br><input name="pseudo" type="text"></p>

<p class="MsoNormal"><b>Votre Adresse postale complète</b>
<br><textarea name="Adresse" rows="3" cols="20"></textarea></p>

<p class="MsoNormal"><b>Nature de l'évènement (Mariage, Anniversaire, Film d'entreprise, Film de fiction etc.)</b>
<br><input name="evenement" type="text"></p>

<p class="MsoNormal"><b>Nombre d’heure(s) et de minute(s) de rushes (totalité de ce vous avez filmé) à traiter</b>
<br>(si vous ne le savez pas, nous nous engageons à vous communiquer leur durée éxacte)
<br><input name="rushes" type="text"></p>

<p class="MsoNormal"><b>Votre Adresse Email</b>
<br><input name="email" type="text"></p>

<p class="MsoNormal"><b>Vous pouvez ici indiquer vos commentaires, questions et attentes</b>
<br><textarea name="Observations" rows="5" cols="40"></textarea></p>

<p class="MsoNormal"><input name="jours_semaine" value="conditionsgenerales" type="checkbox">En cliquant ici je certifie avoir lu et accepté <a href="http://montagedefilms.free.fr/index.php/?conditionsgnrales" target="_blank"> >les conditions générales< </a> applicables aux prestations de montage vidéo</p>

<p class="MsoNormal"><input value=" Envoyer " type="submit"><span style="font-weight: bold;"></p>
</form>[/code]

Le formmail.php
[code]<?php
$TO = "***@free.fr";

$h = "From: " . $TO;

$message = "";

while (list($key, $val) = each($HTTP_POST_VARS)) {
$message .= "$key : $val\n";
}

mail($TO, $subject, $message, $h);

Header("Location: http://<montagedefilms.free.fr/>");

?>[/code]

Pouvez-vous m'aider svp?

UN GRAND MERCI D'AVANCE

10 réponses

Voya 59
 
Lu,

Non ca ne va pas il manque l'essenciel. Le code qui envoie le mail ça devrait donner quelque chose du genre:




<?

// récupère les datas
/////////////////////

if (!isset($_GET['from']))
$from="***@****.com";
else
$from=$_GET['from'];

if (!isset($_GET['destinataire']))
$destinataire="***@****.com";
else
$destinataire=$_GET['destinataire'];

if (!isset($_GET['priority']))
$priority="";
else
$priority=$_GET['priority'];

if (!isset($_GET['objet']))
$objet="";
else
$objet=$_GET['objet'];

if (!isset($_GET['texte']))
$texte="";
else
$texte=$_GET['texte'];

$from = str_replace("%26","&", $from);
$destinataire = str_replace("%26","&", $destinataire);
$objet = str_replace("%26", "&",$objet);
$texte = str_replace( "%26","&",$texte);

$from = str_replace("%27","'", $from);
$destinataire = str_replace("%27","'", $destinataire);
$objet = str_replace("%27", "'",$objet);
$texte = str_replace( "%27","'",$texte);

$from = str_replace("\'","'", $from);
$destinataire = str_replace("\'","'", $destinataire);
$objet = str_replace("\'", "'",$objet);
$texte = str_replace( "\'","'",$texte);

$from = str_replace("%20"," ", $from);
$destinataire = str_replace("%20"," ", $destinataire);
$objet = str_replace("%20"," ",$objet);
$texte = str_replace("%20"," ",$texte);

$from = str_replace("_","<br>", $from);
$destinataire = str_replace("_","<br>", $destinataire);
$objet = str_replace("_","<br>",$objet);
$texte = str_replace("_","<br>",$texte);

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)' );


// Mail contructor

function Mail()
{
$this->autoCheck( true );
}


/* autoCheck( $boolean )
* activate or desactivate the email addresses validator
* ex: autoCheck( true ) turn the validator on
* by default autoCheck feature is on
*/

function autoCheck( $bool )
{
if( $bool )
$this->checkAddress = true;
else
$this->checkAddress = false;
}


/* Subject( $subject )
* define the subject line of the email
* $subject: any valid mono-line string
*/

function Subject( $subject )
{
$this->msubject = strtr( $subject, "\r\n" , " " );
}


/* From( $from )
* set the sender of the mail
* $from should be an email address
*/

function From( $from )
{

if( ! is_string($from) ) {
exit;
}
$this->from= $from;
}


/* To( $to )
* set the To ( recipient )
* $to : email address, accept both a single address or an array of addresses
*/

function To( $to )
{

// TODO : test validité sur to
if( is_array( $to ) )
$this->sendto= $to;
else
$this->sendto[] = $to;

if( $this->checkAddress == true )
$this->CheckAdresses( $this->sendto );

}


/* Cc()
* set the CC headers ( carbon copy )
* $cc : email address(es), accept both array and string
*/

function Cc( $cc )
{
if( is_array($cc) )
$this->acc= $cc;
else
$this->acc[]= $cc;

if( $this->checkAddress == true )
$this->CheckAdresses( $this->acc );

}



/* Bcc()
* set the Bcc headers ( blank carbon copy ).
* $bcc : email address(es), accept both array and string
*/

function Bcc( $bcc )
{
if( is_array($bcc) ) {
$this->abcc = $bcc;
} else {
$this->abcc[]= $bcc;
}

if( $this->checkAddress == true )
$this->CheckAdresses( $this->abcc );
}


/* Body()
* set the body of the mail ( message )
*/

function Body( $body )
{
$this->body= $body;
}


/* Send()
* fornat and send the mail
*/

function Send()
{
// build the headers
$this->_build_headers();

// include attached files
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);
// TODO : trmt res
}

}


/* Organization( $org )
* set the Organisation header
*/

function Organization( $org )
{
if( trim( $org != "" ) )
$this->organization= $org;
}


/* Priority( $priority )
* set the mail priority
* $priority : integer taken between 1 (highest) and 5 ( lowest )
* ex: $m->Priority(1) ; => Highest
*/

function Priority( $priority )
{

if( ! intval( $priority ) )
return false;

if( ! isset( $this->priorities[$priority-1]) )
return false;

$this->priority= $this->priorities[$priority-1];

return true;

}


/* Attach( $filename, $filetype )
* attach a file to the mail
* $filename : path of the file to attach
* $filetype : MIME-type of the file. default to 'application/x-unknown-content-type'
* $disposition : instruct the Mailclient to display the file if possible ("inline") or always as a link ("attachment")
* possible values are "inline", "attachment"
*/

function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" )
{
// TODO : si filetype="", alors chercher dans un tableau de MT connus / extension du fichier
$this->aattach[] = $filename;
$this->actype[] = $filetype;
$this->adispo[] = $disposition;
}


/* Get()
* return the whole e-mail , headers + message
* can be used for displaying the message in plain text or logging it
*/

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;
}


/* ValidEmail( $email )
* return true if email adress is ok - regex from Manuel Lemos (mlemos@acm.org)
* $address : email address to check
*/

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;
}


/* CheckAdresses()
* check validity of email addresses
* if unvalid, output an error message and exit, this may be customized
* $aad : array of emails addresses
*/

function CheckAdresses( $aad )
{
for($i=0;$i< sizeof( $aad); $i++ ) {
if( ! $this->ValidEmail( $aad[$i]) ) {
exit;
}
}
}


/********************** PRIVATE METHODS BELOW **********************************/



/* _build_headers()
* [INTERNAL] build the mail headers
*/

function _build_headers()
{

// creation du header mail

$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";

}



/*
* _build_attachement()
* internal use only - check and encode attach file(s)
*/
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 );

/*
// OLD version - used in php < 3.0.6 - replaced by chunk_split()
$deb=0; $len=76; $data_len= strlen($data);
do {
$ata[$k++]= substr($data,$deb,$len);
$deb += $len;
} while($deb < $data_len );

*/
}
$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();

?>




Là le code génère lui même le mail depuis le serveur.


Bon courrage...
0
Utilisateur anonyme
 
Merci beaucoup pour ta réponse

Je dois mettre ce script dans formmail.php?
0
Utilisateur anonyme
 
Ah oui non d'accord j'ai compris, il ne faut plus appeler de page .php en fait

Merci!
0
Voya 59
 
A adapter au besoin,

C'est le formulaire qui est appelé dans "<form>"


<form method=POST action="formmail.php" >


formmail.php oui! (ne pas oublier les "" ... ça aide surtout dans la clareté du code)

Après bien placer les champs:
from
destinaire
priority
objet
texte


Dans le formulaire ou se trouve "<form method=POST action="formmail.php" > "



Attention entre la méthode "POST" et "GET" (l'envoi des données ne se fait pas de la même manière et surtout la taille du texte disponible n'est pas la même...)

!!! attention mon code est prévu pour une méthode get sinon changer:

if (!isset($_GET['from']))

par

if (!isset($_POST['from']))


(pour From, destinaire, priority, objet, texte)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Utilisateur anonyme
 
D'accord donc dans formmail.php

Par contre je ne comprends pas, je dois changer quoi? Les from priority etc. je dois les changer dans la première partie?
Et que dois-je y mettre? Priority par exemple, à quoi ça correspond?
0
Utilisateur anonyme
 
Et comment l'adapter à mon formulaire?

Merci
0
Voya 59
 
Dans le formulaire rempli par le visteur vous y mettez des champs (zones de texte à remplir).

Ces zones de texte doivent être lues par la page d'envoi (pour savoir quoi envoyer par mail)

Ces champs doivent s'appeler "from" (pour le mail du visiteur), "destinaitaire" (le votre de mail), "texte" pour le contenu du message....

Dans le forumaire que vous affichez (celui que rempli le visiteur) vous utilisez une "méthode" pour faire passer les données vers le fichier qui envoie le mail (formmail.php).

Cette méthode est la méthode "POST" (que l'on trouve dans cette ligne: <form method=POST action="formmail.php" >


Dans le formulaire qui envoie le mail (formmail.php) la méthode qui permet de récupérer les données passées d'un fichier à l'autre doivent être les mêmes.

Dans ce cas dans le formualire qui envoie le mail vous devez changer le méthode de lecture des données:



if (!isset($_GET['from'])) ==> c'est la méthode get qui est employée ici

par

if (!isset($_POST['from'])) ==> pour que la données puisse être récupérée, vous devez placer POST (comme dans la page remplie par le visiteur)





Dans toutes ces lignes vous devez remplacer "GET" par "POST"

if (!isset($_GET['from']))
$from="***@****.com";
else
$from=$_GET['from'];

if (!isset($_GET['destinataire']))
$destinataire="***@****.com";
else
$destinataire=$_GET['destinataire'];

if (!isset($_GET['priority']))
$priority="";
else
$priority=$_GET['priority'];

if (!isset($_GET['objet']))
$objet="";
else
$objet=$_GET['objet'];

if (!isset($_GET['texte']))
$texte="";
else
$texte=$_GET['texte'];



Pour que le fichier fonctionne comme il faut et qu'il récupère bien les données envoyées par le visiteur.
0
Utilisateur anonyme
 
Merci

Et pour mon adresse email, où dois-je la mettre?
0
Voya 59
 
Dans destinataire:


if (!isset($_GET['destinataire']))
$destinataire="***@****.com"; ===> ICI
else
$destinataire=$_GET['destinataire'];



En fait le code que j'ai envoyé permet d'envoyer du mail avec toutes les caractéristiques des mails au destinataires de son choix, avec le suljet, objet... copie carbone et copie cachée.

Dans le cas présent le destinaitaire du mail c'est qui? vous! alors vous pouvez remplacer le code (les 4lignes en italique ci-dessus) par:


$destinataire="***@****.com";


***@****.com ==> correspond à ladresse mail ou va être envoyé le courrier
0
Utilisateur anonyme
 
Merci, j'ai fait les modifs, "get" en post" et mis mon adresse email, mais ça ne marche pas, je ne reçois aucun email

Ca ne vient pas de mon formulaire.php?
0