Web Hosting Talk







View Full Version : Email form have a little problem cant find it!! help!!


luespi
07-17-2009, 02:54 PM
thanks a lot for your help!
you all are really great!!
am kind of new to php


1 this script works fine but when I dont fill the email field I am supposed to be send to "noemail.html" but I just get sent to tryagain.html


2 Is the security well fixed in this email php scritp?

3 The fact that I use lots of rows blank and not, in the messages is not an issue right? That part works fine in my php5

4 if there is a server error I will be sent to servererror.html , right?
I tested that part living the "$to" part in the mail() function empty and it did sent me to servererrror.html
<?php



function spamcheck($field)
{




//--filter_var() sanitizes the e-mail address that is inserted
// --The FILTER_SANITIZE_EMAIL filter removes all forbidden e-mail characters from the inserted string $field=filter_var($field, FILTER_SANITIZE_EMAIL);

//--filter_var() validates the e-mail address that is inserted
// --The FILTER_VALIDATE_EMAIL filter validates the value of the text inserted as an e-mail address



if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}


}









if (isset($_REQUEST['email']))
{//this is a simple check that makes sure the email field not empty

//this is the check that uses the validation function to ensure the email address is valid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
header( "Location: http://mydomain.com.mx/tryagain.html" );

//echo "<br><br><br><br> <center> <body bgcolor=000000> <font size=7 color=ff00> Error: <br> Ese correo no existe <br>o usted ha dejado algunos campos sin llenar <br/><br> haga click en su boton de retroceso para intentarlo de nuevo</a> </font> </center> ";
}
else
{//send email


$email = $_REQUEST['email'] ;
$messagecorto = $_REQUEST['messagecorto'] ;
$asunto = $_REQUEST['asunto'] ;
$name = $_REQUEST['name'] ;
$tel = $_REQUEST['tel'] ;


$message = "-Mensaje enviado desde su página web, con estos datos:

nombre: $name

telefono: $tel

correo: $email

mensaje:
$messagecorto


--Un mensaje de confirmacion se ha enviado al correo de la persona que envio este mensaje--

";





$message2 = "Gracias, usted nos ha enviado un mensaje desde nuestro sitio web, en breve le responderemos.

Aqui repoducimos lo que usted envio:

nombre: $name

telefono: $tel

correo: $email

mensaje:
$messagecorto


--Gracias
---SI USTED NO ENVIO ESTE MENSAJE IGNORE ESTE EMAIL. DISCULPE

";






if(mail( "prueba@mydomain.com.mx","$asunto",$message,"From: su_pagina_de_contacto@mydomain.com.mx") && mail( "$email","en mydomain.com.mx recibimos su mensaje aqui lo reproducimos",$message2,"From: prueba@mydomain.com.mx"))
{


header( "Location: http://mydomain.com.mx/gracias.html" );


}

else
{
header( "Location: http://mydomain.com.mx/servererror.html" );
}


//echo "Thank you for using our mail form! We will get in touch with you soon!";
}









}
else
{
header( "Location: http://mydomain.com.mx/noemail.html" );
//if the "email" field is not filled out the form itself will be displayed.
//echo "<form method='post' action='sendmail.php'>
// Email: <input name='email ' type='text' /><br />
// Subject: <input name='subject' type='text' /><br />
// Message:<br />
// <textarea name='message' rows='15' cols='40'>
// </textarea><br />
// <input type='submit' />
// </form>";
}















?>

Kohrar
07-17-2009, 05:44 PM
thanks a lot for your help!
you all are really great!!
am kind of new to php


1 this script works fine but when I dont fill the email field I am supposed to be send to "noemail.html" but I just get sent to tryagain.html


2 Is the security well fixed in this email php scritp?

3 The fact that I use lots of rows blank and not, in the messages is not an issue right? That part works fine in my php5

4 if there is a server error I will be sent to servererror.html , right?
I tested that part living the "$to" part in the mail() function empty and it did sent me to servererrror.html


#1) An empty string when submitted is still 'set' (thus, your isset($_REQUEST['email']) will still result as true) and is also considered an invalid email address, which is why you are sent to tryagain.html.
Try replacing 'isset($_REQUEST['email'])' with 'if ($_REQUEST['email'] == '')' to actually check for an empty string.

#2) It looks ok, but wouldn't pass $asunto directly into mail() without first making sure only alphanumeric characters are passed. ie: no newlines or other special symbols.
I would use some sort of captcha or a limit on how often a user can send a message using this script since anyone can flood your script with emails to send unwanted mail from your server.

#3) The blank lines throughout the code is not an issue to the compiler, however it is honestly very hard to read.
The blank lines, tabs and spaces within quotes will be part of the message though. So it's a good idea to not indent the contents in your $message and $message2 variables.

#4) From your code, you will get sent to servererror.html when mail() fails. So long as the provided email is valid, and that your mailserver is running, you should be redirected to gracias.html.

Good luck! :)

luespi
07-21-2009, 06:54 PM
Thanks a lot:D:D:D

however

it didnt work

but you were pointingme in the right direction!!!!:D:D:D;););)




i just changed it to this:

and it finnaly worked:

if ($_REQUEST['email'] != '')


thanks alot!!!!!!!