Can some one help me to create a form & send the results to my e mail address?? and cc as well to another one ?
Field Names : Name , Telephone No (should get validated to c the user enters more than 10 numbers) , E Mail address (should get validated to c whether the user has entered a correct e mail format) , Radio button, and commens area please.Submit & reset buttons.We need to make sure that certain feilds such as name , comments cant keep "blank"

Recommended Answers

All 4 Replies

Since you didn't give your email address, nor did you specify the address to CC to I've just put a empty mail function there. If you can provide a email addresses I can help you out. For more on mail() see the PHP.net documentation.

<?php
if($_POST['submit']=="Submit"&&!empty($_POST['name']&&!empty($_POST['phone'])&&strlen($_POST['phone'])>10&&!empty($_POST['email'])&&#
preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/',$_POST['email'])&&!empty($_POST['comments']))
{
  //Form is Valid
  echo "Thanks! Your submission was sent!";
  mail(); //<--Will Not work!! You need a email address, a subject, a body, and headers
  exit(); //Prevents user from seeing the form again
}
?>
<html>
<head>
<title>Form Submission Test</title>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<label for="name">Name: </label><input type="text" name="name" value="<?=$_POST['name']?>"><br/>
<label for="phone">Telephone: </label><input type="text" name="phone" value="<?=$_POST['phone']?>"><br/>
<label for="email">Email: </label><input type="text" name="email" value="<?=$_POST['email']?>"><br/>
<label for="radio">Radio Button</label><input type="radio" name="radio" value="radio1'"><br>
<label for="comments">Comments: </label><textarea name="comments"><?=$_POST['name']?></textarea><br>
<input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset">
</form>
</body>
</html>

Sorry I am new to Forms !!! Got PHP files and JS from a friend , but cant configure them properly

If you don't have a basic understanding then perhaps you should check out this article. Also here is some source for basic usage:

<?
if (isset($_POST['subject']) && $_POST['message']!=='')
    {
    $address = "your_real_email@domain.com"; //change this to the receiving address.
    $subject = "Website Email: ".$_POST['subject'];
    if ($_POST['name']!=='')
        {
        $body = "<table border=0 cellpadding=5 cellspacing=0 width=200><tr><td>".$_POST['message']."<br>
<br>
Yours Sincerely<br>
".$_POST['name']."</td></tr></table>";
        } else {
        $body = "<table border=0 cellpadding=5 cellspacing=0 width=200><tr><td>".$_POST['message'].
        "</td></tr></table>";
        }
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: do_not_reply@your_website_form' . "\r\n";
 
    mail($address,$subject,$body,$headers);
    }
//below displays the form while above processes it.
echo "<form method='post'>Subject: <input type=text value='' maxlength=100 name='subject' size=30><br>
<textarea cols=30 rows=20 name='message'></textarea><br>Name: <input type='text' value='' name='name'>
<input type='submit' value='submit'></form>";
?>

If you don't have a clue what any of that code means then you have some studying to do. That code only uses basic concepts which you would use in every day coding. So perhaps a few php tutorials might help.

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.