· 8 years ago · Apr 24, 2018, 06:18 PM
1SMTP Error: Could not authenticate. Message could not be sent.
2
3function supervisorMail(){
4
5global $error;
6$mail = new PHPMailer();
7$mail->IsSMTP();
8$mail->SMTPDebug = 0;
9$mail->SMTPAuth = true;
10$mail->SMTPSecure = 'ssl';
11$mail->Host = 'smtp.gmail.com';
12$mail->Port = 465;
13$mail->Username = "***@gmail.com";
14$mail->Password = "****";
15$mail->SetFrom("***@gmail.com", "Employee Leave Management System");
16
17$userID=$_SESSION['userID'];
18
19$select_query = mysql_query("SELECT * FROM employee WHERE emp_id = '$userID'");
20$select_sql = mysql_fetch_array($select_query);
21$name=$select_sql['manager_name'];
22var_dump($name);
23
24$select_query1 = mysql_query("SELECT email FROM employee WHERE emp_id='$name'");
25$select_sql1 = mysql_fetch_array($select_query1);
26$email=$select_sql1['email'];
27 var_dump($email);
28
29$mail->Subject = "subject ";
30$mail->Body = "something.";
31$mail_to = $email;
32$mail->AddAddress($mail_to);
33
34if(!$mail->Send())
35{
36 echo "Message could not be sent. <p>";
37 echo "Mailer Error: " . $mail->ErrorInfo;
38 exit;
39}
40
41echo "Message has been sent";
42
43$mail->Username = "@gmail.com";
44$mail->Password = "";
45
46$mail->Username = "********@gmail.com";
47$mail->Password = "********";
48
49<?php
50require 'PHPMailer/PHPMailerAutoload.php';
51$mail = new PHPMailer;
52$mail->SMTPDebug = 2; // Enable verbose debug output
53$mail->isSMTP(); // Set mailer to use SMTP
54$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
55$mail->SMTPAuth = true; // Enable SMTP authentication
56$mail->Username = '*****001@gmail.com'; // SMTP username
57$mail->Password = 'ma****02'; // SMTP password
58$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
59$mail->Port = 465; // TCP port to connect to
60$mail->setFrom('ravi******@gmail.com', 'Mailer'); // Add set from id
61$mail->addAddress('er.ravihirani@gmail.com', 'Ravi Hirani'); // Add a recipient
62//$mail->addAddress('ellen@example.com'); // Name is optional
63//$mail->addReplyTo('info@example.com', 'Information');
64//$mail->addCC('cc@example.com');
65//$mail->addBCC('bcc@example.com');
66//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
67//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
68//$mail->isHTML(true); // Set email format to HTML
69$mail->Subject = 'Here is the subject';
70$mail->Body = 'This is the HTML message body <b>in bold!</b>';
71$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
72if(!$mail->send()) {
73 echo 'Message could not be sent.';
74 echo 'Mailer Error: ' . $mail->ErrorInfo;
75} else {
76 echo 'Message has been sent';
77}
78
79global $password; // <- this added to make script work
80
81 $mail = new PHPMailer(true);
82 try {
83 $mail->isSMTP();
84
85 // Set mailer to use SMTP
86 $mail->Host = '*******.com';
87 $mail->SMTPAuth = true;
88 $mail->Username = 'no-reply@*******.com';
89 $mail->Password = $password;
90 $mail->SMTPSecure = 'tls';
91 $mail->Port = 587;
92 $mail->setFrom('no-reply@*******.com', '******* - DO NOT REPLY');
93
94 //$mail->isHTML(true);
95 $mail->AddAddress($user->email);
96
97 $mail->Subject = "*******";
98 $mail->Body = "*******";
99
100 $mail->send();
101
102 } catch (Exception $e) {
103 echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
104 }