this question has answer here:
im building php form customer , issue collecting datas form has "post" method, , php section complicated me.
first, want use custom html template, displaying well, seems post collecting values brooke. also, $headers datas seem not added (email coming no $from value, no $to value).
i need this. here html , php section. please take note, i'm not javascript programmer, try learn has best knowlege , time goes. i've start nothing.
here form html structure (recaptcha missing normal):
<div class="col-md-offset-1 col-md-10 col-md-offset-1"> <script type="text/javascript"> var recaptchaoptions = { lang : 'fr', }; </script> <style type="text/css"> .field-error .control-label, .field-error .help-block, .field-error .form-control-feedback { color: #ff0039; } .field-success .control-label, .field-success .help-block, .field-success .form-control-feedback { color: #2780e3; } </style> <form method="post" action="envoi_appel_de_service.php"> <p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#337ab7 !important;"> <i class="fa fa-building"></i> informations sur l'adresse du service</p> <!-- nom de la compagnie --> <div class="form-group row"> <label for="nom_compagnie" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">nom de la compagnie</label> <div class="col-sm-8"> <input type="text" class="form-control" id="nom_compagnie" placeholder="le nom de l'entreprise"> </div> </div> <!-- adresse --> <div class="form-group row"> <label for="adresse" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">adresse</label> <div class="col-sm-8"> <input type="text" class="form-control" id="adresse" placeholder="adresse de l'entreprise"> </div> </div> <!-- ville --> <div class="form-group row"> <label for="ville" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">ville</label> <div class="col-sm-8"> <input type="text" class="form-control" id="ville" placeholder="le nom de la ville de l'entreprise"> </div> </div> <!-- province --> <div class="form-group row"> <label for="province" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;" id="province">province</label> <div class="col-sm-5"> <select class="form-control"> <option>alberta</option> <option>colombie-britanique</option> <option>ile-du-prince-edouard</option> <option>manitoba</option> <option>nouveau-brunswick</option> <option>nouvelle-ecosse</option> <option>nunavut</option> <option>ontario</option> <option selected="selected">quebec</option> <option>saskatchewan</option> <option>terre-neuve-labrador</option> <option>territoires du nord-ouest</option> <option>yukon</option> </select> </div> </div> <!-- code postale --> <div class="form-group row"> <label for="code_postale" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">code postale</label> <div class="col-sm-4"> <input type="text" class="form-control" id="code_postale" placeholder="xxx xxx"> </div> </div> <!-- nom de la personne ressource --> <div class="form-group row"> <label for="nom_responsable" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">nom du responsable</label> <div class="col-sm-8"> <input type="text" class="form-control" id="nom_responsable" placeholder="nom de la personne ressource sur place"> </div> </div> <!-- telephone --> <div class="form-group row"> <label for="telephone" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">téléphone</label> <div class="col-sm-8"> <input type="text" class="form-control" id="telephone" placeholder="x xxx xxx-xxx ext xxxx"> </div> </div> <!-- adresse courriel --> <div class="form-group row"> <label for="courriel" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">adresse courriel</label> <div class="col-sm-8"> <input type="email" class="form-control" id="courriel" placeholder="adresse courriel valide"> </div> </div> <p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#a41313 !important;"> <i class="fa fa-print"></i> informations sur le produit</p> <!-- marque --> <div class="form-group row"> <label for="marque" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">marque</label> <div class="col-sm-6"> <input type="text" class="form-control" id="marque" placeholder="marque du produit"> </div> </div> <!-- modèle --> <div class="form-group row"> <label for="modele" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">numéro de modèle</label> <div class="col-sm-6"> <input type="text" class="form-control" id="modele" placeholder="veuillez inscrire le numéro de modèle"> </div> </div> <!-- garantie --> <div class="form-group row"> <label for="garantie" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">garantie</label> <div class="col-sm-6"> <input type="text" class="form-control" id="garantie" placeholder="est-ce que le produit est sous garantie?"> </div> </div> <!-- description du problème --> <div class="form-group row"> <label for="description" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">description du problème</label> <div class="col-sm-8"> <textarea class="form-control" rows="4" id="description"></textarea> </div> </div> <p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#337ab7 !important;"> <i class="fa fa-calendar-o"></i> préférences pour le rendez-vous</p> <!-- disponibilité --> <div class="form-group row"> <label for="disponibilite" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">disponibilité</label> <div class="col-sm-8"> <input type="text" class="form-control" id="disponibilite" placeholder="quel est le meilleur moment pour vous joindre?"> </div> </div> <!-- coordonnées --> <div class="form-group row"> <label for="coordonnees" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">coordonnées</label> <div class="col-sm-8"> <input type="text" class="form-control" id="coordonnees" placeholder="optionel"> </div> </div> <p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#a41313 !important;"> <i class="fa fa-lock"></i> sécurité anti-spam</p> <!-- validation recaptcha franco google --> <div class="form-group row"> <label for="input12" class="col-sm-4 form-control-label text-right" style="padding-top:28px !important;">sécurité anti-spam</label> <div class="col-sm-8"> <div class="g-recaptcha" data-sitekey="masking"></div> </div> </div> <!-- soumettre --> <div class="form-group row"> <label for="submit" class="col-sm-4 form-control-label text-right"> </label> <div class="col-sm-8"> <button name="submit" type="submit" value="submit" class="btn btn-primary">soumettre</button> </div> </div> </form>
and here php section:
<?php if (isset($_post["submit"])) { $to = "masking"; $from = $_post['courriel']; $subject = "réception d'un appel de service"; $nom_compagnie = $_post['nom_compagnie']; // required $adresse = $_post['adresse']; // required $ville = $_post['ville']; $province = $_post['province']; $code_postale = $_post['code_postale']; $nom_responsable = $_post['nom_responsable']; $courriel = $_post['courriel']; $marque = $_post['marque']; $numero_modele = $_post['numero_modele']; $garantie = $_post['garantie']; $description = $_post['description']; $disponibilite = $_post['disponibilite']; // required $coordonnees = $_post['coordonnees']; // required $headers = 'from: '.$courriel."\r\n". 'reply-to: '.$from."\r\n" . 'x-mailer: php/' . phpversion(); $message = " <!doctype html public \"-//w3c//dtd html 4.01 transitional//en\"> <html> <head> <title>appel de service (rempli sur le site internet)</title> <style type=\"text/css\"> h1,h2,h3,h4,h5,h6 { font-family: cambria, \"hoefler text\", \"liberation serif\", times, \"times new roman\", serif; color: #272727; } </style> </head> <body> <h2 style=\"font-size: 1.25em; font-family: gotham, ʼhelvetica neueʼ, helvetica, arial, sans-serif;\">vous avez reçu une demande dʼappel de service en ligne.</h2> <table width=\"500\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\"> <tbody> <tr> <td colspan=\"2\" align=\"left\" valign=\"middle\" bgcolor=\"#84bdec\"><h3>inations sur lʼadresse du service</h3></td> </tr> <tr> <td width=\"155\" align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">nom de la compagnie</td> <td width=\"313\" align=\"left\" valign=\"middle\">$nom_compagnie</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">adresse</td> <td align=\"left\" valign=\"middle\">$adresse</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">ville</td> <td align=\"left\" valign=\"middle\">$ville</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">province</td> <td align=\"left\" valign=\"middle\">$province</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">code postale</td> <td align=\"left\" valign=\"middle\">$code_postale</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">nom du responsable</td> <td align=\"left\" valign=\"middle\">$nom_responsable</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">téléphone</td> <td align=\"left\" valign=\"middle\">$telephone</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">adresse courriel</td> <td align=\"left\" valign=\"middle\">$courriel</td> </tr> </tbody> </table> <br> <table width=\"500\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\"> <tbody> <tr> <td colspan=\"2\" align=\"left\" valign=\"middle\" bgcolor=\"#84bdec\"><h3>informations sur le produit</h3></td> </tr> <tr> <td width=\"155\" align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">marque</td> <td width=\"313\" align=\"left\" valign=\"middle\">$marque</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">numéro de modèle</td> <td align=\"left\" valign=\"middle\">$numero_modele</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">garantie</td> <td align=\"left\" valign=\"middle\">$garantie</td> </tr> <tr bgcolor=\"#d5d5d5\"> <td colspan=\"2\" align=\"left\" valign=\"middle\">description du problème :</td> </tr> <tr> <td height=\"75\" colspan=\"2\" align=\"left\" valign=\"top\">$description</td> </tr> </tbody> </table> <br> <table width=\"500\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\"> <tbody> <tr> <td colspan=\"2\" align=\"left\" valign=\"middle\" bgcolor=\"#84bdec\"><h3>préférences pour le rendez-vous</h3></td> </tr> <tr> <td width=\"155\" align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">disponibilité</td> <td width=\"313\" align=\"left\" valign=\"middle\">$disponibilite</td> </tr> <tr> <td align=\"left\" valign=\"middle\" bgcolor=\"#d5d5d5\">coordonnées</td> <td align=\"left\" valign=\"middle\">$coordonnees</td> </tr> </tbody> </table> </body> </html> "; // set content-type when sending html email mail($to, $courriel, $message, $headers, "from: $from\n" . "mime-version: 1.0\n" . "content-type: text/html; charset=iso-8859-1"); } ?>
has can see, values empty, headers too. im stuck , had no idea why doesn't work. if can me please, lot.
there few errors in code (not missing name attributes).
you have no name
attributes of inputs , error reporting have thrown it.
i.e.: $_post['courriel']
need change email input to: (you can't rely on "id" alone).
<input type="email" name = "courriel" class="form-control" id="courriel" placeholder="adresse courriel valide"> ^^^^^^^^^^^^^^^^^
and following same pattern other inputs.
however, , stated in comments. header fail.
you're using 5 parameters. there 5th available, isn't used you're doing.
mail($to, $courriel, $message, $headers, "from: $from\n" . "mime-version: 1.0\n" . "content-type: text/html; charset=iso-8859-1");
the syntax is:
- to:
- subject:
- message:
- headers
as per manual on mail()
:
the 5th parameter is:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
example of 5 parameters:
mail('nobody@example.com', 'the subject', 'the message', null, '-fwebmaster@example.com');
an example manual on using 4 parameters , sending html:
<?php // multiple recipients $to = 'aidan@example.com' . ', '; // note comma $to .= 'wez@example.com'; // subject $subject = 'birthday reminders august'; // message $message = ' <html> <head> <title>birthday reminders august</title> </head> <body> <p>here birthdays upcoming in august!</p> <table> <tr> <th>person</th><th>day</th><th>month</th><th>year</th> </tr> <tr> <td>joe</td><td>3rd</td><td>august</td><td>1970</td> </tr> <tr> <td>sally</td><td>17th</td><td>august</td><td>1973</td> </tr> </table> </body> </html> '; // send html mail, content-type header must set $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; // additional headers $headers .= 'to: mary <mary@example.com>, kelly <kelly@example.com>' . "\r\n"; $headers .= 'from: birthday reminder <birthday@example.com>' . "\r\n"; $headers .= 'cc: birthdayarchive@example.com' . "\r\n"; $headers .= 'bcc: birthdaycheck@example.com' . "\r\n"; // mail mail($to, $subject, $message, $headers); ?>
add error reporting top of file(s) find errors.
<?php error_reporting(e_all); ini_set('display_errors', 1); // rest of code
sidenote: displaying errors should done in staging, , never production.
Comments
Post a Comment