First i have to tell you that my english is not perfect , but i hope you will understand me.
I got an problem with A Mail form on my website , I downloaded an template that have e mail form in contact page , but i dont know where to input my e-mail as owner who will recieve e mails that people send me from this form.
And normaly after pressing send there should come an message if it was sucessfully sent or not .
Here are the codes , and tell me how to fix it . How to bring this form working normaly how it should.
______________________________
I got 2 files named " MailHandler.php " and " MailHandler.ashx " . This Files are located in an folder named " bin " .
MailHandler.php code :
PHP Code:
<?php
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";
Thats all , can anyone tell me please how to make it working correctly and where to put my e mail which should reciee all messages sent from this form ?
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
if(mail){
echo "<html>";
echo "<head>";
echo "<title>HQWebs - Mail Sent</title>";
echo "</head>";
echo "<body bgcolor='#000000'>";
echo "<center><img src='http://www.hqwebs.eu/images/mailsent.jpg'></center>";
echo "</body>";
echo "</html>";
}else{
echo "Cannot Send your mail for error";
}
?>
But This Phone field is not working , when you send an message i got , e mail , name , text message from sender , but there is not the phone number , what should i do to fix that too ?
Its telling me " Numbers is :0038766336703 <fightingforlove@greenmail.netphone> "
And it should be " Phone Number is : 0038766336703 <fightingforlove@greenmail.net> "
Can you fix this code please ? And thank you very much for spending time on my problem!
Hmm , can anyone tell me how to add option "Required" to some fields ?
So when this required field in not filled then the message wont be sent , and he will get this message which is placed in this php " Cannot Send your mail for error " .
Try the following code. I've cleaned up yours a bit to make it easier to read.
It's untested but simple enough that it should work.
I've commented it to help you
PHP Code:
<!DOCTYPE html> <html> <?php $fields = array('message','email'); // required fields go in here $errors=false; if(isset($_POST['send'])) { array_walk($_POST, 'cleanMe'); // Clean up the input $to = "hqwebs.eu@gmail.com"; $name=$_POST['name']; $phone = $_POST['phone']; $email = $_POST ['email']; $message = $_POST['message']. "\n\n Phone Number is " .$phone; $headers = "From:" . $email ;
/** * Checks fields to see if they are empty */ foreach($fields as $field) { if( strlen($_POST[$field]) == 0 ) { $errors = true; break; } }
if(!$errors) // If none of the required fields produced an error then try to email { mail($to,$name,$message,$headers);
if(mail) { echo "Mail Sent."; } else { echo "Cannot Send your mail for error"; } } else // One or more of the required fields wasn't filled in { echo 'Fields marked with a * are required'; }
} /** * * Clean up input from the user * @param type $data * @return string */ function cleanMe($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data, ENT_QUOTES); return $data; } ?> <form id="" method="post" contact-form"> <fieldset> <label>Name</label> <input type="text" name = "name" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''" /><br />
Hey CkirSter , thank you for spending your time on my problem , but this codes are not working correctly .
After filling all fields and press send button , nothing happens , and i dont become the e mail , and there is not coming the message if it was sent sucessfully or not . Its not working :S
Can you take a look on this codes and find where is problem ? Thank you very much.
I might be confusing you a little.
I was using minkoko's last code as an example. I also never tested it but can see at second glance the
PHP Code:
mail($to,$name,$message,$headers);
if(mail)
{
echo "Mail Sent.";
}
else
{
echo "Cannot Send your mail for error";
}
should read
PHP Code:
if(mail($to,$name,$message,$headers))
{
echo "Mail Sent.";
}
else
{
echo "Cannot Send your mail for error";
}
The code I added to it is there to give you a simple example of setting errors and stopping the script calling the "mail" function if there are errors.