formulaire de validation HTML PHP avec e-mail

  • beaner
  • Novice
  • Novice
  • No Avatar
  • Inscription: Déc 09, 2009
  • Messages: 15
  • Status: Offline

Message Janvier 26th, 2010, 2:18 pm

Salut à tous,
J'ai un formulaire HTML qui, lorsqu'elles sont présentées appelle un fichier php qui envoie un e-mail HTML à l'adresse e-mail fournie. J'aimerais qu'il se rediriger vers une page d'erreur si l'ensemble des champs spécifiés ne sont pas remplis correctement. Les travaux de redirection si le contenu est correctement saisie, mais ne fonctionne pas si tous les champs sont vides. Toutes les idées
Code: [ Select ]
$fname = substr($_POST[fname], 0, 100);
$name = substr($_POST[name], 0, 100);
$address = substr($_POST[address], 0, 100);
$city = substr($_POST[city], 0, 100);
$province = substr($_POST[province], 0, 100);
$postalcode = substr($_POST[postalcode], 0, 100);
$email = substr($_POST[email], 0, 100);
$msg = substr($_POST[message], 0, 800);

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) header ("Location: http://www/content_error.html");

if (empty($_POST[fname])) header ("Location: http://www/content_error.html");
if (empty($_POST[name])) header ("Location: http://www/error.html");

//define the receiver of the email
$to = $email;
//define the subject of the email
$subject = 'ExtendBar Coupon Request';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: noReply@";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.


ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Thank you for your interest in ExtendBar.

Please click on the link below to recieve your in-store coupon.
Print out the coupon and bring it with you to a participating pharmacy.



Please do not hesitate to contact us at anytime should you have any further questions.
We look forward to hearing from you!

Kind Regards,

Staff


--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<html>
<head>
<title>ExtendBar Coupon Request</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style2 {font-size: 11px}
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
-->
</style>
</head>
<body>
<div><img src="emailHeader.jpg" width="640" height="89"></div><br/>
 <p><span class="style1"><span class="style2"><strong>Thank you for your interest in ExtendBar. 
  </strong><br>
 <br>
Please click on the link below to recieve your in-store coupon. <br>
Print out the coupon and bring it with you to a participating pharmacy.<br>
 <br>
 <a href="" target="_blank">CLICK HERE TO RECIEVE YOUR EXTENDBAR COUPON</a></span></span><br/> 
 <BR>
</p>
<p class="style3"> Please do not hesitate to contact us at anytime should you have any further questions.<BR>
 We look forward to hearing from you! </span></span></p>
<p class="style3">Kind Regards,</p>
<p class="style3"> <strong></strong><BR>

1</p>


</body>
</html>

--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
include 'content_thanks.html';
include 'data/ICOM/ExtendBarQueryICOM.php';
?>
  1. $fname = substr($_POST[fname], 0, 100);
  2. $name = substr($_POST[name], 0, 100);
  3. $address = substr($_POST[address], 0, 100);
  4. $city = substr($_POST[city], 0, 100);
  5. $province = substr($_POST[province], 0, 100);
  6. $postalcode = substr($_POST[postalcode], 0, 100);
  7. $email = substr($_POST[email], 0, 100);
  8. $msg = substr($_POST[message], 0, 800);
  9. if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) header ("Location: http://www/content_error.html");
  10. if (empty($_POST[fname])) header ("Location: http://www/content_error.html");
  11. if (empty($_POST[name])) header ("Location: http://www/error.html");
  12. //define the receiver of the email
  13. $to = $email;
  14. //define the subject of the email
  15. $subject = 'ExtendBar Coupon Request';
  16. //create a boundary string. It must be unique
  17. //so we use the MD5 algorithm to generate a random hash
  18. $random_hash = md5(date('r', time()));
  19. //define the headers we want passed. Note that they are separated with \r\n
  20. $headers = "From: noReply@";
  21. //add boundary string and mime type specification
  22. $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
  23. //define the body of the message.
  24. ob_start(); //Turn on output buffering
  25. ?>
  26. --PHP-alt-<?php echo $random_hash; ?> 
  27. Content-Type: text/plain; charset="iso-8859-1"
  28. Content-Transfer-Encoding: 7bit
  29. Thank you for your interest in ExtendBar.
  30. Please click on the link below to recieve your in-store coupon.
  31. Print out the coupon and bring it with you to a participating pharmacy.
  32. Please do not hesitate to contact us at anytime should you have any further questions.
  33. We look forward to hearing from you!
  34. Kind Regards,
  35. Staff
  36. --PHP-alt-<?php echo $random_hash; ?> 
  37. Content-Type: text/html; charset="iso-8859-1"
  38. Content-Transfer-Encoding: 7bit
  39. <html>
  40. <head>
  41. <title>ExtendBar Coupon Request</title>
  42. <style type="text/css">
  43. <!--
  44. .style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
  45. .style2 {font-size: 11px}
  46. .style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
  47. -->
  48. </style>
  49. </head>
  50. <body>
  51. <div><img src="emailHeader.jpg" width="640" height="89"></div><br/>
  52.  <p><span class="style1"><span class="style2"><strong>Thank you for your interest in ExtendBar. 
  53.   </strong><br>
  54.  <br>
  55. Please click on the link below to recieve your in-store coupon. <br>
  56. Print out the coupon and bring it with you to a participating pharmacy.<br>
  57.  <br>
  58.  <a href="" target="_blank">CLICK HERE TO RECIEVE YOUR EXTENDBAR COUPON</a></span></span><br/> 
  59.  <BR>
  60. </p>
  61. <p class="style3"> Please do not hesitate to contact us at anytime should you have any further questions.<BR>
  62.  We look forward to hearing from you! </span></span></p>
  63. <p class="style3">Kind Regards,</p>
  64. <p class="style3"> <strong></strong><BR>
  65. 1</p>
  66. </body>
  67. </html>
  68. --PHP-alt-<?php echo $random_hash; ?>--
  69. <?
  70. //copy current buffer contents into $message variable and delete current output buffer
  71. $message = ob_get_clean();
  72. //send the email
  73. $mail_sent = @mail( $to, $subject, $message, $headers );
  74. //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
  75. echo $mail_sent ? "Mail sent" : "Mail failed";
  76. include 'content_thanks.html';
  77. include 'data/ICOM/ExtendBarQueryICOM.php';
  78. ?>
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Janvier 26th, 2010, 2:18 pm

  • nexuslite
  • Newbie
  • Newbie
  • No Avatar
  • Inscription: Fév 11, 2010
  • Messages: 10
  • Loc: Keizer, OR
  • Status: Offline

Message Février 11th, 2010, 5:52 am

Ce n'est probablement pas le meilleur moyen mais je voudrais vérifiez chacun des domaines qui doivent être remplis ont une longueur.

Code: [ Select ]
$fname = substr($_POST[fname], 0, 100);
$name = substr($_POST[name], 0, 100);
$address = substr($_POST[address], 0, 100);
$city = substr($_POST[city], 0, 100);
$province = substr($_POST[province], 0, 100);
$postalcode = substr($_POST[postalcode], 0, 100);
$email = substr($_POST[email], 0, 100);
$msg = substr($_POST[message], 0, 800);

$error = 0;
$error = strlen($fname)?$error:1;
$error = strlen($name)?$error:1;
$error = strlen($address)?$error:1;
$error = strlen($city)?$error:1;
$error = strlen($province)?$error:1;
$error = strlen($postalcode)?$error:1;
$error = strlen($email)?$error:1;
$error = strlen($msg)?$error:1;


if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) || $error)
    header ("Location: http://www/content_error.html");
  1. $fname = substr($_POST[fname], 0, 100);
  2. $name = substr($_POST[name], 0, 100);
  3. $address = substr($_POST[address], 0, 100);
  4. $city = substr($_POST[city], 0, 100);
  5. $province = substr($_POST[province], 0, 100);
  6. $postalcode = substr($_POST[postalcode], 0, 100);
  7. $email = substr($_POST[email], 0, 100);
  8. $msg = substr($_POST[message], 0, 800);
  9. $error = 0;
  10. $error = strlen($fname)?$error:1;
  11. $error = strlen($name)?$error:1;
  12. $error = strlen($address)?$error:1;
  13. $error = strlen($city)?$error:1;
  14. $error = strlen($province)?$error:1;
  15. $error = strlen($postalcode)?$error:1;
  16. $error = strlen($email)?$error:1;
  17. $error = strlen($msg)?$error:1;
  18. if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) || $error)
  19.     header ("Location: http://www/content_error.html");

Afficher de l'information

  • Total des messages de ce sujet: 2 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 209 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC