...

View Full Version : PHP Form to Mail Help



zoe20
01-22-2010, 07:39 AM
ok friends i created my form and am not good at php and one can help me make a php form basing on my form i created on my site please?

This is Markup



<div class="Welcome">
<h2>Contact Form</h2>
<p><strong>Looking for a Designer ? Send me your details right now!!. </strong></p>
<div class="bg"></div>
<form action="contact.php" method="post" name="contactform" id="contactform">
<ol>
<li>
<label for="name">your name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="company">Company Name</label>
<input id="company" name="company" class="text" />
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" class="text" />
</li>
<li>
<label for="message">message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" />
</li>
<li class="buttons"></li>
</ol>
</form>
</div>
This is php


<?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";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "zo_ee_20@hotmail.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
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!';
}
}
?>

abduraooft
01-22-2010, 09:24 AM
ok friends i created my form and am not good at php and one can help me make a php form basing on my form i created on my site please?
Could you please specify the problem that you are facing?

zoe20
01-22-2010, 01:40 PM
Could you please specify the problem that you are facing?

Form is not processing at all . Please help me . Am not good at php. sems some thing wrong with my php

zoe20
01-23-2010, 12:26 PM
sorry for the bump. Any help please?

abduraooft
01-23-2010, 12:48 PM
Form is not processing at all . Please help me . Am not good at php. sems some thing wrong with my php I'm sorry to say that the answer is still vague. What is not processing - the validation part or the mail sending part?

It gives me the message

Invalid email address entered when I tried that code at my end without filling anything int hat form.

PS:

if(!$_POST) exit; A better approach is

if(isset($_POST)){
// process the submitted data here

}
else {
// do something if required
}

zoe20
01-24-2010, 06:33 PM
ok i changed my code.i tested it and i am getting mails to my root e-mail.But surprisingly am getting mails from like this : myemail@kiwi.cryl.net instead of myemail@hotmail.com. Some thing wrong with the script??


<?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";
$errors = 1;
}
if ($errors == 1) {
echo $error;
} else {
$values = array('name', 'email', 'message');
$required = array('name', 'email', 'message');

$your_email = "zo_ee_20@hotmail.com";
$email_subject = "New Message: " . $_POST['subject'];
$email_content = "new message:\n";

foreach ($values as $key => $value) {
if (in_array($value, $required)) {
if ($key != 'subject' && $key != 'company') {
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!';
}
}
?>

tchot
01-26-2010, 06:41 PM
zoe,
I got the same php coding but can't get it to work either.
have you fixed the problem?
thanks

zoe20
01-27-2010, 07:03 PM
zoe,
I got the same php coding but can't get it to work either.
have you fixed the problem?
thanks
Yes my form is processing but the problem i mentioned in my earlier post still persisting. Me getting mails like this myemail@myemail@kiwi.cryl.net instead of myemail@hotmail.com. .net instead of myemail@hotmail.com. I dont know what is this kiwi.cryl is all about. seems some thing wrong in my php:(. Need some experts to solve my problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum