contact form

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
WiZARD
Moderator
Moderator
Posts: 1240
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Fri Jun 29, 2007 12:47 am

khujo56 wrote:Hi guys

i created a contact form in html and a code in php to send the info to my e-mail account. the problem i have is that i want an error to show if nothing or some of the info is not filled in when i press the submit button. if i click the submit button with nothing filled out, it says the info has been sent to my e-mail account. can anyone look at my code and see what i'm doing wrong. below is the php code.

<?php
if(isset($_POST['submit'])) {
$to = "jnr1975@hotmail.com";
$subject = "Contact Info";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$errors = '';

if ( empty($name_field) ) $errors .= 'fill out name<br/>';
if ( empty($email_field) ) $errors .= 'fill out email<br/>';
if ( empty($message) ) $errors .= 'fill out message<br/>';

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";


if ( !empty($errors) ) {
echo $errors;
} else {
mail($to, $subject, $body);
echo "Data has been submitted to $to!";
}
?>
you do not close first brace {

Code: Select all

<?
if (isset($_POST['submit'])) 
{
  $to = "jnr1975@hotmail.com";
  $subject = "Contact Info";
  $name_field = $_POST['name'];
  $email_field = $_POST['email'];
  $message = $_POST['message'];

  $errors = '';

  if ( empty($name_field) ) $errors .= 'fill out name<br/>';
  if ( empty($email_field) ) $errors .= 'fill out email<br/>';
  if ( empty($message) ) $errors .= 'fill out message<br/>';

  $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";


  if ( !empty($errors) ) 
  {   echo $errors; } 
  else 
  { 
    mail($to, $subject, $body);
    echo "Data has been submitted";
  } 
}
?>
And I recommend do not use your e-mail address... Someone can use it ;)
"Sex,Drugs and Rock&Roll " replaced at "Sucks,Bugs and Plug&Play";
Image
Post Reply