Skip to content
WJunction - Webmaster Forum

contact.php need guide

Status
Not open for further replies.
Please help me expect my code.
here is the GUI

th_Capture.jpg


Code:
<?php

if(!$_POST) exit;

$email = $_POST['email'];


$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered, please re-enter your email. example : test@email.com";
$errors=1;
}
if($errors==1) echo $error;
else{

$values = array ('name','email','message');
$required = array('name','email','message');
 
$your_email = "karyawansufi@gmail.com";
$email_subject = "New Message";
$email_content = "new message:\n";
 
for( $i = 0 ; $i < count( $values ) ; ++$i ) {
	for( $c = 0 ; $c < count( $required ) ; ++$c ) {
		if( $values[$i]==$required[$c] ) {
			echo $required[$x];
			if( empty($_POST[$values[$i]]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
		}
	}
	$email_content .= $values[$i].': '.$_POST[$values[$i]]."\n";
}

foreach($values as $value){
  if(in_array($value,$required)){
    if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
    $email_content .= $value.': '.$_POST[$value]."\n";
  }
}
 
if(mail($your_email,$email_subject,$email_content)) {
	echo 'Message sent!'; 
} else {
	echo 'ERROR!';
}
}
?>
 

1 comment

Its the weirdest contact page i've seen so far.
I've quickly written this one instead.

I'm not sure it works. As I dont use the build-in mail function.
It also wont check the email adress to be valid..

But atleast now you got something.. IF this works :P

PHP:
<?php
if(!empty($_POST['sendmail'])){
 if(strlen($_POST['email']) < 3)
   die('No email found');
 if(strlen($_POST['content']) < 3)
   die('No content found');

 $to = 'youremail@email.com' ; // Replace this with your email


 $subject = 'New Message';
 $content = 'New Message from '.$_POST['email'].' :'."\n\n".$_POST['content'];

  if(mail($to,$subject,$content))
   echo 'sent';
  else
   echo 'failed';

}else{
?>
<html>
 <head>
  <title>
    Mail Form
  </title>
 </head>
 <body>
  <form method="post">
   <input type="text" name="email" value="your email" /><br />
   <textarea name="content"></textarea><br />
   <input type="submit" name="sendmail" value="sendmail" />
  </form>
 </body>
</html>
<?php
}
?>
 
Status
Not open for further replies.

About the author

P
New Member · Joined
i am freaking IT maniac hacking
4
Messages
0
Reactions
1
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom