Jump to content

PHP Form mail Script


Recommended Posts

For some strange reason this dude wants a full flash website, ok.. then he wants a form to send to his email..ok so..

 

I have a general understanding of php, but its at the beginner level. I got this code from http://htmlcenter.com/blog/php-form-validation/.

It works, but when I put <code> into it, the form still sends, I dont really understand the

 

!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s".

 

whats the difference between testing for

 

if (!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$msg))

 

and

 

if(!preg_match(”/[^0-9\ ]+$/”,$field_name_2))

 

Which one should I be using for what inputs?

 

<?php

    $msg = stripslashes($_GET['message']);

      $email = stripslashes($_GET['email']);

      $name = stripslashes($_GET['name']);

  $to = "[email protected]";

  $subject = "Inquiry Form";

  $message = "Message: $msg,\n\n Name: $name,\n\n Email: $email";

 

 

function check_field1($msg)

{

  if (!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$msg))

  return TRUE;

  else

  return FALSE;

 

}

 

function check_field2($email)

{

  if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$email))

  return TRUE;

  else

  return FALSE;

 

}

 

function check_field3($name)

{

  if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$name))

  return TRUE;

  else

  return FALSE;

 

}

 

$error=0;

 

if(!check_field1($msg))

{

  echo "Illegal input $msg in Message";

  $error++;

}

if(!check_field2($email))

{

  echo "Illegal input $email in Email";

  $error++;

}

if(!check_field3($name))

{

  echo "Illegal input $name in Name";

  $error++;

}

 

if($error == 0)

{

  mail($to,$subject,$message);

}else{

  echo "Number of errors: $error";

}

 

?>

 

 

Is there an easier way to do this??? any info will help i'm lost i've been searching the internet for a couple days, and it doesn't really help when i dont understand the code very well..

 

thanks

 

marc

Link to comment
https://forums.phpfreaks.com/topic/114474-php-form-mail-script/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.