la validación de formularios HTML con PHP e-mail
- beaner
- Novice


- Registrado: Dic 09, 2009
- Mensajes: 15
- Status: Offline
Hola a todos,
Tengo un formulario HTML que envía las llamadas cuando un archivo PHP que envía un correo electrónico HTML en el correo electrónico proporcionada. Me gustaría volver a dirigir a una página de error si todos los campos especificados no son llenados correctamente. Las obras redirigir si el contenido se introduce de forma incorrecta, pero no funciona si todos los campos están en blanco. Alguna idea
Tengo un formulario HTML que envía las llamadas cuando un archivo PHP que envía un correo electrónico HTML en el correo electrónico proporcionada. Me gustaría volver a dirigir a una página de error si todos los campos especificados no son llenados correctamente. Las obras redirigir si el contenido se introduce de forma incorrecta, pero no funciona si todos los campos están en blanco. Alguna idea
Código: [ 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';
?>
$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';
?>
- $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';
- ?>
- Anonymous
- Bot


- Registrado: 25 Feb 2008
- Mensajes: ?
- Loc: Ozzuland
- Status: Online
Enero 26th, 2010, 2:18 pm
- nexuslite
- Newbie


- Registrado: Feb 11, 2010
- Mensajes: 10
- Loc: Keizer, OR
- Status: Offline
Esto probablemente no es la mejor manera, pero quisiera comprobar para asegurarse de que cada uno de los campos que tienen que ser llenados con longitud.
Código: [ 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");
$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");
- $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");
Página 1 de 1
Para responder a este tema que necesita para ingresar o registrarse. Es gratis.
Publicar Información
- Total de mensajes en este tema: 2 mensajes
- Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 178 invitados
- No puede abrir nuevos temas en este Foro
- No puede responder a temas en este Foro
- No puede editar sus mensajes en este Foro
- No puede borrar sus mensajes en este Foro
- No puede enviar adjuntos en este Foro
