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

22203A00008_practical14

The document outlines a laboratory experiment for 6th semester Computer Engineering students, focusing on implementing PHPMailer for sending emails. It includes sample PHP code for sending a test email and a form for sending emails with user input and attachments. The document also contains sections for grading and teacher signatures.

Uploaded by

spandaa257
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)
4 views9 pages

22203A00008_practical14

The document outlines a laboratory experiment for 6th semester Computer Engineering students, focusing on implementing PHPMailer for sending emails. It includes sample PHP code for sending a test email and a form for sending emails with user input and attachments. The document also contains sections for grading and teacher signatures.

Uploaded by

spandaa257
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/ 9

DEPARTMENT OF COMPUTER ENGINEERING

Subject: WBP Subject Code: 225619


Semester:6th Semester Course: Computer Engineering
Laboratory No: L001C Name of Subject Teacher: Prof. Sneha Patange
Name of Student: Shravan Salgaonkar Roll Id: 22203A0027

Experiment No: 14
Aim of Experiment Implement working of phpmailer.

 Implement working of

phpmailer. Ans :

Code:
<?php
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\
SMTP; use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'onyyvitrrghxntsa'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted

$mail->Port = 587; // TCP port to connect to


$mail->setFrom(' [email protected] ', 'PHPMailer');
//$mail->addAddress('[email protected]', 'Abhinav'); // Add a recipient
$mail->addAddress(' [email protected] ', 'Hi'); // Add a
recipient //

$mail->addReplyTo('[email protected]', 'Information');
$mail->addAttachment('c:\Users\Downloads\WBP_14.pdf'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test Mail from PHPMailer';
$mail->Body = '<h1>This is the testmail sent from PHPMailer </h1>'; if(!
$mail-
>send()) {
echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
Page | 1
echo 'Message has been sent';

Page | 2
}

Output :

Page | 3
Page | 4
2. Implement Phpmailer with custom user input.

Ans :

Code :
<?php
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\
SMTP; use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$mail = new PHPMailer(true); try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Replace with your SMTP server
$mail->SMTPAuth = true;
$mail->Username = ' [email protected] ' ; // SMTP username
$mail->Password = 'erxxfdcabasmdikf'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Recipients
$mail->setFrom(' [email protected] ', 'PHPMailer');
$mail->addAddress($_POST['email']);
// Attachments

Page | 5
if (!empty($_FILES['attachment']['name'])) {
$mail->addAttachment($_FILES['attachment']['tmp_name'],
$_FILES['attachment']['name']);
}
// Content
$mail->isHTML(true);
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['message'];
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Send Email with Attachment</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<label for="email">Recipient Email:</label>
<input type="email" name="email" required><br><br>
<label for="subject">Subject:</label>

<input type="text" name="subject" required><br><br>


<label for="message">Message:</label>
<textarea name="message" required></textarea><br><br>
<label for="attachment">Attachment:</label>
<input type="file" name="attachment"><br><br>
<input type="submit" value="Send Email">
</form>
</body>
</html>

Output :

Page | 6
Page | 7
Page | 8
Grade and Process Related Product Related Dated Sign
Dated (35) (15)
Signature of
Teacher

Page | 9

You might also like