0% found this document useful (0 votes)
13 views5 pages

Vaanga pt.2

This document provides a PHP program for sending and receiving emails using the PHPMailer library. It includes an HTML form for user input (email, subject, and message) and PHP code to configure SMTP settings for sending emails through Gmail. The program also handles success and error messages upon sending the email.

Uploaded by

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

Vaanga pt.2

This document provides a PHP program for sending and receiving emails using the PHPMailer library. It includes an HTML form for user input (email, subject, and message) and PHP code to configure SMTP settings for sending emails through Gmail. The program also handles success and error messages upon sending the email.

Uploaded by

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

Practical No.

14
Program Code : Write a program to send and receive mail using PHP

<!DOCTYPE html>

<html lang="en" dir="ltr">

<head>

<meta charset="utf-8">

<title>Send Email</title>

</head>

<body>

<form class="" action="send.php" method="post">

Email <input type="email" name="email" value=""> <br>

Subject <input type="text" name="subject" value=""> <br>

Message <input type="text" name="message" value=""> <br>

<button type="submit" name="send">Sendk/button>

</form>

</body>

</html>

Index.php :

<?php

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

require 'phpmailer/src/Exception.php';

require 'phpmailer/src/PHPMailer.php';

require 'phpmailer/src/SMTP.php';

if (isset($_POST["send"])) {

try {
$mail = new PHPMailer(true);

// SMTP configuration

$mail->isSMTP();

$mail->Host = 'smtp.gmail.com';

$mail->SMTPAuth = true;

$mail->Username = '[email protected]'; // Your Gmail address

$mail->Password = 'dkkfltmzjramvqzs'; // Your Gmail app password

$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Correct encryption type

$mail->Port = 465;

// Sender and recipient settings

$mail->setFrom('[email protected]', 'Your Name'); // Your Gmail address

$mail->addAddress($_POST["email"]); // Recipient's email address

// Email content

$mail->isHTML(true);

$mail->Subject = $_POST["subject"];

$mail->Body = $_POST["message"];

$mail->send();

echo "

<script>

alert('Email sent successfully!');

document.location.href = 'index.php';

</script>

";

} catch (Exception $e) {

echo "

<script>
alert('Email could not be sent. Mailer Error: {$mail->ErrorInfo}');

</script>

";

?>

Output :

You might also like