Practical No.
14
1. Write a program to send and receive mail using PHP.
Code :-
<!DOCTYPE html>
<html>
<head>
<title>Send and Receive Mail using PHP</title>
</head>
<body>
<?php
$to ="[email protected]";
$subject ="Test email";
$message ="This is a HTML message.";
$headers = "From:[email protected]";
$headers .="Cc:[email protected]";
$retValue=mail($to, $subject, $message, $headers);
if ($retValue==true) {
echo "<p>Email sent successfully!</p>";
} else {
echo "<p>Failed to send email.</p>";
?>
</body>
</html>
2. Write a simple program to check that emails are valid.
Code :-
<!DOCTYPE html> if ($_SERVER["REQUEST_METHOD"] ==
<html> "POST") {
<head> $email = $_POST['email'];
<title>Email Validation</title> if (filter_var($email,
</head> FILTER_VALIDATE_EMAIL)) {
<body> echo "<b><p style='color: green;'>Valid
<h2>Check Email Validity</h2> Email Address</p></b>";
<form method="post"> } else {
<label for="email">Enter Email:</label> echo "<b><p style='color: red;'>Invalid
<input type="text" id="email" Email Address</p></b>";
name="email" required> }
<input type="submit" value="Check"> }
</form> ?>
<?php </body>
</html>
Output :-