Jump to content

Adding Html To Php


shoyle

Recommended Posts

Note: I changed $mail to $email;if (isset($_POST['nombre']) || isset($_POST['telefono']) || isset($_POST['email'])) { $nombre = $_POST['nombre']; $telefono = $_POST['telefono']; $email = $_POST['email']; $mensaje = $_POST['mensaje']; $pattern = '/[^0-9]/'; if(empty($nombre) || empty($telefono) || empty($email)) { $errormsg.= "<p style=\"color: red;\">Please Fill In Empty Fields.</p>"; } if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) { $errormsg.= "<h2>Vuelva a la pagina anterior, ingrese una direccion de e-mail válida-.</h2>\n"; $errormsg.= "<h2>La informacion no fue ingresada.</h2>\n"; } if (empty($POST['mensaje'])) { $errormsg.= "<h2>Vuelva a la pagina anterior, rellene todas las casillas.</h2>\n"; } if (preg_match($pattern, $telefono)) { $errormsg.= "<p style=\"color: red;\">Invalid Telephone Number entered.</p>"; } if($errormsg == "") // if no errors found go to page.... (this should be at end, below all validation conditions) { header("Location: http://www.laradialautomoviles.com/gracias.html"); } }

Link to comment
Share on other sites

Theres a mistake on the empty message part scince it comes up every time i clik trhe submit button, but it all seems to be ok :) :S I pasted my e-mail part and it doesnt work with that either:

<?php$nombre = "";$telefono = "";$email = "";$mensaje = "";$errormsg = "";if (isset($_POST['nombre']) || isset($_POST['telefono']) || isset($_POST['email'])){$nombre = $_POST['nombre'];$telefono = $_POST['telefono'];$email = $_POST['email'];$mensaje = $_POST['mensaje'];$pattern = '/[^0-9]/';if(empty($nombre) || empty($telefono) || empty($email)){$errormsg.= "<p style=\"color: red;\">Rellene todos los campos.</p>";}if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))){$errormsg.= "<h2>Ingrese una direccion de e-mail válida-.</h2>\n";}if (empty($POST['mensaje'])){$errormsg.= "<h2>Rellene todas las casillas.</h2>\n";}if (preg_match($pattern, $telefono)){$errormsg.= "<p style=\"color: red;\">El numero de telefono no es valido.</p>";}$header = 'From: ' . $mail . " rn";$mensaje = "Este mensaje fue enviado por " . $nombre . " ";$mensaje .= "Su telefono es: " . $telefono . " ";$mensaje .= "Su e-mail es: " . $mail . " ";$mensaje .= "Mensaje: " . $_POST['mensaje'] . " " ;$mensaje .= "Enviado el " . date('d/m/Y', time());//-----------------------------------------------------////----------------------------------------------------//$para = 'admin@pumsho.com';$asunto = 'Contacto desde pagina web';mail($para, $asunto, utf8_decode($mensaje), $header);if($errormsg == "") // if no errors found go to page.... (this should be at end, below all validation conditions){header("Location: [url="http://www.laradialautomoviles.com/gracias.html&quot%3b%29;"]http://www.laradialautomoviles.com/gracias.html");[/url]}} ?>

Link to comment
Share on other sites

works awsome! youre the man!!the only lil problem is thet if they make a mistake they get the "enter valid phone" for example, but on the mesage part you see this: Este mensaje fue enviado por "who sent the mesage" Su telefono es: "the wrong phone number" Su e-mail es: "the email" Mensaje: "the mesage" Enviado el 18/08/2009 so when you correect the mistake you recive an email with the information 2 times repeeted. I dont know if its the order thigs are or wht but I gess it must be that.and a lil one, insted of teh header location gracias.html can i change that for something like mmm echo "your mesage wass sent correctly" would the echo work and apear inside the page correctly?

Link to comment
Share on other sites

You haven't told it not to send the E-mail if the information was wrong:

mail($para, $asunto, utf8_decode($mensaje), $header);if($errormsg == "") // if no errors found go to page.... (this should be at end, below all validation conditions){header("Location: http://www.laradialautomoviles.com/gracias.html");}

Try this instead:

if($errormsg == "") // if no errors found go to page.... (this should be at end, below all validation conditions){  mail($para, $asunto, utf8_decode($mensaje), $header);  header("Location: http://www.laradialautomoviles.com/gracias.html");}

Link to comment
Share on other sites

this is the problem:$mensaje = "Este mensaje fue enviado por " . $nombre . " ";$mensaje .= "Su telefono es: " . $telefono . " ";$mensaje .= "Su e-mail es: " . $mail . " ";$mensaje .= "Mensaje: " . $_POST['mensaje'] . " " ;$mensaje .= "Enviado el " . date('d/m/Y', time());$mensaje is already used for the message content from $_POST['mensaje']. The form uses this to show the message content previously entered after an error is found (prevents re-entering message repeatedly), but now you have added all the email contents to this variable.solution, rename '$mensaje' above to something like '$emailcontent'ALSO '$mail' should be '$email'the '$errormsg' can be used to show 'Congratulations Email Sent' message, but it might be good idea to empty all the field content as well, see below:if($errormsg == "") // if no errors found, send email go to page.... (this should be at end, below all validation conditions){mail($para, $asunto, utf8_decode($emailcontent), $header); //Note change '$mensaje' to $emailcontent $errormsg="<p style=\"color: #00FF00;\"> Message sent Congratulations</p>"; $nombre = "";$telefono = "";$email = "";$mensaje = ""; //header("Location: http://www.laradialautomoviles.com/gracias.html");}

Link to comment
Share on other sites

cool that works!! but haha this is getting funnyer every time, now I get 2 emails for every time it submits , one that says the e-mail adress of the person who sent it as the sender and only the message inside but not the phone or name, and a second message with the address of my hosting as the sender and all the correct info such as phone name and so on.. :)

Link to comment
Share on other sites

check out Sending email in PHP which shows you how to send mail with all options below.$headers = 'To: Mary <mary@example.com>' . "\r\n";$headers .= 'Cc: Kelly <kelly@example.com>' . "\r\n";$headers .= 'Bcc: John <john@example.com>, Peter <peter@example.com>' . "\r\n";$headers .= 'From: Matthew <matthew@example.com>' . "\r\n";$headers .= 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Link to comment
Share on other sites

when I thought it wass all perfect: SURPRISE!!! when i receive the mail sent through the page, i see : from : laradialautomoviles (the name of the site) and this: (laradialautomoviles@magic.dreamhost.com) I dont understand where that came from !! need help again!!! hehe

Link to comment
Share on other sites

That's the default address on the server. If you don't want to use the default you need to give it a from address to use, you can use a header for that also like with BCC. If the server ignores your from address and uses its own, it's probably best to contact your host and ask them why.

Link to comment
Share on other sites

when I look into my php it says $header = 'From: ' . $email . " rn"; witch means that it should say the e-mail of the person who sent it and that way I can also clik on reply and it will reply to the e-mail the person entered. maybe theres something wrong with my code?

<?php$nombre = "";$telefono = "";$email = "";$mensaje = "";$errormsg = "";if (isset($_POST['nombre']) || isset($_POST['telefono']) || isset($_POST['email'])){$nombre = $_POST['nombre'];$telefono = $_POST['telefono'];$email = $_POST['email'];$mensaje = $_POST['mensaje'];$pattern = '/[^0-9]/';if(empty($nombre) || empty($telefono) || empty($email)){$errormsg.= "<p style=\"color: red;\">Rellene todos los campos.</p>";}if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))){$errormsg.= "<p style=\"color: red;\">Ingrese una direccion de e-mail válida.</p>";}if (empty($_POST['mensaje'])){$errormsg.= "<p style=\"color: red;\">Rellene todas las casillas.</p>";}if (preg_match($pattern, $telefono)){$errormsg.= "<p style=\"color: red;\">El numero de telefono no es valido.</p>";}$para = 'mymail@mail.com';$asunto = 'Contacto desde pagina web';$header = 'From: ' . $email . " rn";$emailcontent = "Este mensaje fue enviado por: " . $nombre . " ";$emailcontent .= "Su telefono es: " . $telefono . " ";$emailcontent .= "Su e-mail es: " . $email . " ";$emailcontent .= "Mensaje: " . $_POST['mensaje'] . " " ;$emailcontent .= "Enviado el " . date('d/m/Y', time());//----------------------------------------------------if($errormsg == "") // if no errors found, send email go to page.... (this should be at end, below all validation conditions){mail($para, $asunto, utf8_decode($emailcontent), $headers); //Note change '$mensaje' to $emailcontent$errormsg="<p style=\"color: #009afc;\"> Gracias, su mensaje ha sido enviado.</p>";$nombre = "";$telefono = "";$email = "";$mensaje = "";}} ?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...