Jump to content

Simple PHP form not working :S


colleyboy

Recommended Posts

Hi there,

 

Am trying to make a PHP mail script that is sent when the button is pressed.  When the button is pressed it refreshes the page and does not send?  Can anyone help please:

 


<?php
$emailaddress = "[email protected]";  //please replace this with your address

$mail = $_POST['Email'];
$porukaa = $_POST['Message'];
$poruka = str_replace("\r", '<br />', $porukaa);
//START OF THANKS MESSAGE
//you may edit $thanks message. this is a message which displays when user sends mail from your site
$thanks = "
<p align='left' STYLE='font-family:arial;font-size:16px;color:#bed2df;'><br>

<b>Your message has successfully been sent and we will contact you as soon as we can.  Many Thanks!<br></b>
<br>
You will receive a copy of the message at your email address <b>($mail).<br>A member of our team will reply to 

you as soon as possible<br></b></p>";
//do not edit nothing below this line  until comment (ME) say so if you don't have skills with PHP
//END OF THANKS MESSAGE

if($_POST['submitform']) 
{

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$Phone = $_POST['Phone'];
$Regarding = $_POST['Regarding'];
$require = $_POST['require'];
$browser = $HTTP_USER_AGENT;
$ip = $_SERVER['REMOTE_ADDR'];

$dcheck = explode(",",$require);
while(list($check) = each($dcheck)) 
{
	if(!$$dcheck[$check]) {
	$error .= "You have not filled this field(s): <b>$dcheck[$check]</b>.<br>";
	}
}
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[[email protected]]+$", $Email))){
$error .= "Wrong e-mail.<br>This e-mail address <b>$Email</b> - is not valid. Please enter correct e-

mail address.";
}
if($error)
{
echo $error;
echo '<br><a href="#" onClick="history.go(-1)">Please try again.</a>';
}
else
{
//START OF INCOMING MESSAGE (this message goes to your inbox)
$message = "

You have received a message from your websites contact us page:

Name: $Name:

E-mail: $Email

Phone Number: $Phone

Subject: $Regarding

Message: $Message

-----------------------------
Browser: $browser
IP: $ip
";
//END OF INCOMING MESSAGE (this message goes to your inbox)

$subject = "Message from Systems Hydroponics Website - Message was sent by $Name"; //subject OF YOUR INBOX 

MESSAGE sent to you

$subject2 = "You have successfully sent message from Systems Hydroponics!"; //subject of OUTGOING MESSAGE - 

edit this
//OUTGOING MESSAGE TEXT
$message2 = "You have sent a message to Systems Hydroponics:
-----------------------------
Name: $Name

E-mail: $Email

Phone Number: $Phone

Subject: $Regarding

Message: $Message

-----------------------------
";
//END OF outgoing MESSAGE


mail($emailaddress,"$subject","$message","From: $Name <$Email>");
mail($Email,"$subject2","$message2","From: <$nasaadresa>");
echo "$thanks";
}
}
else{

echo '
<br>
<form name="contactform" action="'.$PHP_SELF.'" method="post">
<input type="hidden" name="require" value="Name,Message">
  
<p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Name:<BR>
<input name="Name" size="30" STYLE="font-family:arial;font-size:16px;color:#000000;text-align:left;"></p>

      
<p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Telephone Number:<BR>
<input name="Phone" size="30" STYLE="font-family:arial;font-size:16px;color:#000000;text-align:left;"></p>
      
<p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">E-mail*:<BR>
<input name="Email" size="30" STYLE="font-family:arial;font-size:16px;color:#000000;text-align:left;"></p>

<p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Subject:<BR>

<select name="Regarding">
<option value="When is the store opening?">When is the store opening?</option>
<option value="Hydroponics Products">Hydroponics Products</option>
<option value="Hydroponics Brands">Hydroponics Brands</option>
<option value="Making An Order">Making An Order</option>
<option value="General Question">General Question</option>
<option value="Other">Other</option>
</select></p>

<p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">Message*:<BR>
<textarea name="Message" rows="10" cols="70" STYLE="font-family:arial;font-size:16px;color:#000000;text-

align:left;"></textarea></p>
      
<p align=left STYLE="font-family:arial;color:#bed62f;font-size:16px;">
<input type="submit" value="Send Message to Systems Hydroponics" name="submitform" STYLE="font-

family:arial;color:#000000;font-size:16px;font-weight:bold;background-color:#bed2df;">
</p>
   
</form>';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/264668-simple-php-form-not-working-s/
Share on other sites

Also, since some browsers tend to mangle the attributes of a submit button, it's better to use this to check whether the form has been submitted or not:

if( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) {

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.