Log in

View Full Version : Need Simple contact form



bootersbooters
01-30-2012, 02:45 PM
need a simple contact form
which has name details etc columns and when the user hits the submit button, i should receive in my email

thanks

traq
01-30-2012, 03:25 PM
try google? (http://lmgtfy.com/?q=php+contact+form)

there are plenty of free scripts out there. try to find one that was written for php5 (older versions are often buggy, incompatible with newer php versions, and/or have security problems).

if you're looking for someone to write or install a script for you, you should post in the paid help (http://www.dynamicdrive.com/forums/forumdisplay.php?f=30) forum.

bootersbooters
01-30-2012, 06:06 PM
tried google but none of them work :mad:

traq
01-30-2012, 08:46 PM
?
do you mean they don't do what you want, or that you couldn't install them successfully?

ankush
02-01-2012, 06:54 AM
try to learn not just copy paste

form.htm

<html>
<head><title>Form</title>
</head>
<body>
<form name="sendmail" action="sendmail.php" method="post">
Name:<input type="text" name="name" /><br />
Email:<input type="text" name="email" /><br />
<input type="submit" value="Send Mail" />
</form>
</body>
</html>

sendmail.php

<?php
// fetching form values
$name= $_POST['name'];
$email= $_POST['email'];

$to="youremailhere";
$subject="Form details";
$header="from: $name <$email>";
$message.="Hi \r\n\n";
$message.="Someone submitted the form, see the details below: \r\n\n";
$message.="\n Name: $name \r";
$message.="\n Email: $email";

// send email
$sendmail = mail($to,$subject,$message,$header);

if(isset($sendmail))
{
echo "Mail sent";
}
else
{
echo "can't send mail";
}

?>

traq
02-01-2012, 03:28 PM
First, how will giving out code to be copy/pasted help anyone learn not to copy/paste?

Second, isset($sendmail) will always be true - you just set it to the return value of the mail() function. If mail() didn't work, then $sendmail will be FALSE, but it will still be 'set'.

ankush
02-02-2012, 05:03 AM
ok bro

then should i do this?


if($sendmail)
{
echo "Mail sent";
}
else
{
echo "can't send mail";
}

djr33
02-02-2012, 06:45 AM
Probably like this:

if($sendmail!==FALSE)
But there might be other problems with the script. I haven't tested it.

(Note the three comparison symbols there-- !== -- and that's necessary, including the double equals signs. It means "not exactly equal to" rather than just != which means "not roughly equivalent to" [based on differing types of variables like 0 and FALSE])

traq
02-02-2012, 05:09 PM
You could also skip assigning a variable and just check the return value of the function directly:
if( mail( $to,$subject,$message,$header ) === TRUE ){ print 'mail sent!'; }
else{ print 'mail failed!'; }


But there might be other problems with the script. I haven't tested it.

you should also validate and/or sanitize the user input before sending it off in an email.

Even though you aren't intentionally sending the message in HTML format, there's no way to guarantee that your mail server won't (helpfully) add that mime-type, or that the email client won't see html tags in the (user-submitted) text and (helpfully) try to parse it.