-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpmailer2.php
65 lines (57 loc) · 2.37 KB
/
phpmailer2.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
63
64
65
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendmail($tomail, $totmailname , $subject, $message)
{
include("dbconnection.php");
$sqledit = "SELECT * FROM setting where settingtype=SMTP";
$qsqledit = mysqli_query($con,$sqledit);
echo mysqli_error($con);
$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 Composers autoloader
require PHPMailer/src/Exception.php;
require PHPMailer/src/PHPMailer.php;
require 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_STARTTLS; // 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(cc@example.com);
//$mail->addBCC(bcc@example.com);
// 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("mvaravinda@gmail.com", "Aravind" ,"Hello", "how are you");
?>