i am new to php.... please send me a code tat will help me create a form n direct it to my home page and send the information of the form to my email

Recommended Answers

All 13 Replies

I think that you are not new to php, in fact I think you don't want to learn PHP. If I'm wrong show us some effort, not just "ask code".

I think that you are not new to php, in fact I think you don't want to learn PHP. If I'm wrong show us some effort, not just "ask code".

I know the basics.. not that i dont want to .. not able to create a link to my maill.. wen i say submit it doesnt get submited...
this is the exact cod e i have typed .. wen i say submit it opens the mail.php file n its blank.. nor have i recieved a mail :(
:(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body><form action="mail.php" method="post">
Your Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br><br>
Comments<br>
<textarea name="comments"></textarea><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

named it trial .html

and
<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}

$name=$_POST;
checkOK($name);
$email=$_POST;
checkOK($email);
$comments=$_POST;
checkOK($comments);
$to="vardhani_subramaian@yahoo.com;
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
named this mail.php
please help me !!

your code seems fine...

if(mail($to, "Comment from your website", $message, "from: $email") {
header("location: index.html"); // This will redirect your visitor when the email has been sent
} else {
echo("Message was not sent");
}

just a bone, the opening tag, you have <? instead of <?php. I know this works on some configurations, but for maximum compatibility used <?php
Otherwise, like that other dude said it seems just fine. Also, for this code to work you need to have an smtp server configured on the host machine. If possible, have the smtp server output screen open while you run the script and see what it says. Good luck.

the code i posted above does that...

$to = "your@email.com";
$email = $_POST["email"];
$subject = "Comment to your website";
$message = $_POST["message"];
$headers = "from: $email";

if(mail($to, $subject, $message, $headers)){
    headers("location: index.html");
} else {
    echo("Your message was not sent");
}

Your host isn't GoDaddy is it? The reason I ask is because a recent client of mine hosts with them and I couldn't figure out what was wrong with the mail script. After a little research I found that they have the mail() function as well as many others disabled on their servers.

godaddy? The firm I work for uses them and the mail function works. I think something is wrong internally with the script, because with that if/else clause it's bound to output something, and it doesn't. Maybe it never gets that far.

To the OP, put echos after every line to see where it stops executing, if that's the problem.

I'm sure that your firm doesn't use the $3.99/month small business plan though. Here is a list of disabled functions straight from the phpinfo page: getmyinode, getopt, getrusage, extension_loaded, dl, mysql_pconnect, crack_check, crack_closedict, crack_getlastmessage, crack_opendict, fsockopen, pfsockopen, mysql_list_dbs, mysql_stat, ini_get, ini_get_all, ini_alter, ini_set, get_current_user, get_defined_constants, get_include_path, php_ini_scanned_files, php_uname, phpcredits, restore_include_path, set_include_path, set_time_limit, version_compare, zend_version, getmypid, getmyuid, getmygid, assert_options, assert, fopen, fwrite, fread, file, fpassthru, file, mail, opendir, readdir, closedir

I'd assume that a big host such as godaddy wouldn't disable the mail function. Mail is an important function in PHP

Alright.. There are few mistakes in your mail script. \n should be put in "". Well, Here is the corrected code.

<?php //mail.php
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}

$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$comments=$_POST['comments'];
checkOK($comments);
$to="existing.user@gmail.com";
$message=$name."just filled in your comments form. They said: \n". $comments ."\n\nTheir e-mail address was:".$email;
if(mail($to,"Comments From Your Site",$message,"From: $email.\n")) {
echo "Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>

Hope it helps..

thank u so much ... it worked !! n i could see the output tooo ,.... tat was of gr8 help naveen thank u !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.