NEED HELP (Contact Form Issue)

Discussion in 'HTML & Website Design' started by sanchyclub, Jul 20, 2011.

  1. #1
    Hi,

    My PHP code is not working perfectly for my html5 webpage. I need to use (*) for my name and email field of contact form but that code is not supporting! anyone can send me message without data but I'm using code for my name and email field that you must enter data otherwise it will show error.

    Please take a look on my code...

    I'm using following php code-

    <?php
    extract($_REQUEST);
    $to = 'sanchyclub@gmail.com';
    //Mail Test
    //$to = 'sanchyclub@gmail.com';
    $subject = 'Message From ssanChy.com';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";
    $message = '<html><head></head><body><h1>Proposal Request</h1>';
    $message .= 'Subject : '.$sub.'<br /><br />Name : '.$name.'<br />';
    $message .= 'Email : '.$email.'<br /><br />';
    if(isset($text))
    {
    $message .= 'Comments : '.$text.'<br /><br />';
    }
    $message .= "---------------------------------------------------------------------<br />Message from ssanChy.com<br /></body></html>";
    if($name!="" && $email!="")
    {
    	$send = mail($to, $subject, $message, $headers);
    }
    if($send)
    {
    	echo '<h2>Your Message Has Been Sent!</h2><br />I will reply you within a short time.<br />Thanks you.';
    }
    else
    {
    	echo('Try again!');
    }
    ?>
    PHP:
    And following code for HTML5 webpage-

          <form action="sendmail.php" method="get">
          	<p><input type="text" name="name"  value="Your Name" id="name" onblur="if (this.value == ''){this.value = 'Your Name'; }" onfocus="if (this.value == 'Your Name') {this.value = '';}"></p>
            <p><input type="text" name="email" value="Your Email" id="email"  onblur="if (this.value == ''){this.value = 'Your Email'; }" onfocus="if (this.value == 'Your Email') {this.value = '';}"></p>
            <p><input type="text" name="sub" value="Your Site" id="sub" onblur="if (this.value == ''){this.value = 'Your Site'; }" onfocus="if (this.value == 'Your Site') {this.value = '';}"></p>
            <p><textarea cols="20" rows="4" name="text" id="text" onblur="if (this.value == ''){this.value = 'Your Message'; }" onfocus="if (this.value == 'Your Message') {this.value = '';}" >Your Message</textarea></p>
            <p><input type="submit" name="submit" value="Send Message" class="button"></p>
          </form>
    
    HTML:
    I think you may understand what I want to say, please help to fix that issue.

    Thanks,
     
    sanchyclub, Jul 20, 2011 IP