Practical No.
14
Exercise No. 1
<?php
include('smtp/PHPMailerAutoload.php');
$msg = "This is a sample of SMTP Email Service.";
echo smtp_mailer('[email protected]', 'Email Test',
$msg);
function smtp_mailer($to, $subject, $msg){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 0; // Disable debug output
$mail->Username = "
[email protected]";
$mail->Password = "yaofvokwlwslgken"; // App Password
$mail->SetFrom("
[email protected]");
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AddAddress($to);
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
return 'Email Sent Successfully!';
}
}
?>
Output: