-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpmailer.php
62 lines (56 loc) · 2.3 KB
/
phpmailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendmail($tomail, $totmailname , $subject, $message)
{
include("databaseconnection.php");
$sqledit = "SELECT * FROM mail_setting where settingtype='SMTP'";
$qsqledit = mysqli_query($con,$sqledit);
$rsedit = mysqli_fetch_array($qsqledit);
$smtpdetails = unserialize($rsedit['settingdetails']);
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
// Load Composer's autoloader
require_once 'PHPMailer/src/Exception.php';
require_once 'PHPMailer/src/PHPMailer.php';
require_once 'PHPMailer/src/SMTP.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try
{
//Server settings
$mail->SMTPDebug = false; // SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = $smtpdetails['smtpserver']; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $smtpdetails['loginid']; // SMTP username
$mail->Password = $smtpdetails['password']; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = $smtpdetails['smtpport'];
// TCP port to connect to
//Recipients
$mail->setFrom($smtpdetails['loginid'], $smtpdetails['mailsender']);
$mail->addAddress($tomail, $totmailname); // Add a recipient
$mail->addAddress($tomail); // Name is optional
$mail->addReplyTo($tomail, $totmailname);
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = 'Mail Receieved';
$mail->send();
echo 'Message has been sent';
}
catch (Exception $e)
{
echo "Message could not be sent. Mailer Error: {
$mail->ErrorInfo}";
}
}
//sendmail("[email protected]", "Raj shekar" , "Mail from Local Server", "This is messages");