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
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
try google?
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 forum.
tried google but none of them work![]()
?
do you mean they don't do what you want, or that you couldn't install them successfully?
try to learn not just copy paste
form.htm
sendmail.phpHTML Code:<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>
PHP Code:<?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";
}
?>
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'.
ok bro
then should i do this?
PHP Code:if($sendmail)
{
echo "Mail sent";
}
else
{
echo "can't send mail";
}
Probably like this:
But there might be other problems with the script. I haven't tested it.Code:if($sendmail!==FALSE)
(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])
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
You could also skip assigning a variable and just check the return value of the function directly:you should also validate and/or sanitize the user input before sending it off in an email.PHP Code:if( mail( $to,$subject,$message,$header ) === TRUE ){ print 'mail sent!'; }
else{ print 'mail failed!'; }
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.
Last edited by traq; 02-02-2012 at 05:26 PM.
ankush (02-03-2012)
Bookmarks