0% found this document useful (0 votes)
4 views4 pages

1214phps

The document contains HTML forms for user input, including name, address, and mobile number, with corresponding PHP scripts to process and display the submitted data. It also includes a practical example of sending an email using a form, with validation for email addresses and prevention of header injection. The PHP code ensures that the email is sent successfully or provides an error message if it fails.

Uploaded by

shagunyadav1430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

1214phps

The document contains HTML forms for user input, including name, address, and mobile number, with corresponding PHP scripts to process and display the submitted data. It also includes a practical example of sending an email using a form, with validation for email addresses and prevention of header injection. The PHP code ensures that the email is sent successfully or provides an error message if it fails.

Uploaded by

shagunyadav1430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Code:

Html

<!DOCTYPE html>
<html>
<head>
</head><body> <form action="t10.php" method="post">
Name: <input type ="text" name ="name">
Add: <input type ="text" name="address">
<input type ="submit"> </form>
</body></html> Php
code:
<html>
<body>
Welcome :<?php echo $_POST['name'];?>
Your Address :<?php echo $_POST['address'];?>
</body>
</html>
HTML Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body> <form action="t10.php" method="get">
Name: <input type ="text" name ="name">
Add: <input type ="text" name="address">
<input type ="submit">
</form>
</body>
</html>
Php code:<html>
<body>
Welcome :<?php echo $_POST['name'];?>!
Your Address :<?php echo $_POST['address'];?>
</body>
</html>
Html Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action ="t11.php"method="get">
<label>Moblie Number :</label>
<input type="tex" name="moblieno" id="moblieno">
<input type="submit" value="submit">
</form>
</body>
</html>
Php code: <?php
if(isset($_GET['moblieno']))
{
echo"<p> Moblie Number :".$_GET['moblieno']."</p>"; }?>
Practical no 14
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = filter_var($_POST["to"], FILTER_SANITIZE_EMAIL);
$from = filter_var($_POST["from"], FILTER_SANITIZE_EMAIL);
$subject = htmlspecialchars(strip_tags($_POST["subject"]));
$message = htmlspecialchars(strip_tags($_POST["message"]));
// Validate email addresses
if (!filter_var($to, FILTER_VALIDATE_EMAIL) || !filter_var($from,
FILTER_VALIDATE_EMAIL)) {
echo "Invalid email address.";
exit;}
// Prevent email header injection
if (preg_match("/(\r\n|\n|\r)/", $to) || preg_match("/(\r\n|\n|\r)/", $from)) {
echo "Invalid input detected.";
exit;}
$headers = "From: " . $from . "\r\n" .
"Reply-To: " . $from . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if ("mail($to, $subject, $message, $headers)") {
echo "Email sent successfully.";
} else {
echo "Email failed to send.";
}}?>
<form method="post">
<label for="to">To:</label><br>
<input type="email" name="to" id="to" required><br><br>
<label for="from">From:</label><br>
<input type="email" name="from" id="from" required><br><br>
<label for="subject">Subject:</label><br>
<input type="text" name="subject" id="subject" required><br><br>
<label for="message">Message:</label><br>
<textarea name="message" id="message" required></textarea><br><br>
<input type="submit" value="Send">
</form>

Output::

You might also like