PHPMailer XAMPP SMTP Authentication failed - php

I'm trying to use PHPMailer to send e-mail from my local virtual host on XAMPP with the code below. I have enabled extension=php_openssl.dll in php.ini, still I get the error messages below. Anyone knows why?
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "xxx";
$mail->Password = "xxx";
$email = "xxx#gmail.com";
$name = "Test";
$email_from = "xxx#gmail.com";
$name_from = "Test";
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
echo "Fail - " . $mail->ErrorInfo;
}
Error output:
SMTP ERROR: Password command failed: 534-5.7.14
SMTP Error: Could not authenticate.

For those having issues with failing authentication using PHPMailer, and all settings and credentials are good, try using this:
$mail->AuthType = 'LOGIN';
in the PHP that is attempting to send the email.
I struggled for the longest, until I added this.
Cheers.

Related

Connection with Gmail SMTP cannot be established whith my php script

I want to make just a basic email sending script. Because I want to run it on localhost I use Gmail SMTP. I have both enabled IMAP settings and I allowed access from less secure apps. Surprisingly, I still cannot connect. Everytime I try, I get the error SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Why is that happening? I am using this code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit'])){
$to = $_POST['email'];
$subject = "First email";
$txt = "Do you want our service?";
//require_once('PHPMailer/PHPMailer.php');
require_once "PHPMailer\PHPMailer.php";
require_once "PHPMailer\SMTP.php";
require_once "PHPMailer\Exception.php";
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->isHTML();
$mail->Username = "myemailnotimportant#gmail.com";
$mail->Password = "password123";
$mail->SetFrom('myemailnotimportant#gmail.com', 'Sir Walter Scott');
$mail->Subject = $subject;
$mail->Body = $txt;
$mail->AddAddress($to);
if ($mail->Send()) {
echo "email sent";
} else {
echo "Something is wrong: <br><br>" . $mail->ErrorInfo;
}
}
?>

PHPMailer redirecting to GitHub

When I try to run a simple PHPMailer test script it is redirecting me to GitHub site.
My script is given below. Can someone please help?
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../PHPMailer/src/PHPMailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587 or 465
$mail->IsHTML(true);
$mail->Username = "myaccountname";
$mail->Password = "mypassword";
$mail->setFrom('fromemailid', 'from name');
$mail->Subject = 'Test Mail';
$mail->Body = 'Test mail body';
$mail->AddAddress("someone#gmail.com");
if (!$mail->send())
{echo "Mailer Error: " . $mail->ErrorInfo;
return false;
} else {
return true;
}
?>
Which folder you exactly adding your code. As see your code

PHPMailer Error - multiple errors

Could not access file: http://localhost/k/d/filename.pdf
2014-07-28 16:20:10 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
(10060) SMTP connect() failed. Mailer Error: SMTP connect() failed.
I am trying to send an email. I'm using XAMPP and PHPMailer, and I have no idea what I'm doing wrong. I've looked up tons of similar issues, but I can't find my error.
require("PHPMailer/class.phpmailer.php");
require 'PHPMailer/class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "username#gmail.com";
$mail->Password = "password";
$webmaster_email = "username#gmail.com";
$email=$_POST['email'];
$name=$_POST['email'];
$mail->From = "username#gmail.com";
$mail->FromName = "User Name";
$mail->AddAddress($_POST['email'],$_POST['email']);
$mail->AddReplyTo("username#gmail.com","User Name");
$mail->WordWrap = 50;
$mail->AddAttachment($_POST['file']);
$mail->IsHTML(true);
$mail->Subject = "sent document";
$mail->Body = "Here is the document you requested. Thank you.";
$mail->AltBody = "Here is the document you requested from myITpc. Thank you.";
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
$_POST['email'] contains an email address, such as joe.shmo#hotmail.com and $_POST['file'] contains a local filepath, like http://localhost/folder/file.pdf.
Thanks!

Sending mail in PHP using Hotmail smtp

I am trying to send mail in PHP using Hotmail Smtp. But I am getting error as below:
2014-03-13 06:59:01 CLIENT -> SERVER: EHLO site.com
2014-03-13 06:59:01 CLIENT -> SERVER: AUTH LOGIN
2014-03-13 06:59:01 SMTP ERROR: AUTH command failed: 504 5.3.3 AUTH mechanism LOGIN not available
2014-03-13 06:59:01 CLIENT -> SERVER: QUIT SMTP connect() failed. Mailer Error: SMTP connect() failed.
Please would anyone suggest me what I am doing wrong??
My code :
error_reporting(E_STRICT);
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(); //Initialize a new PHPMailer object;
//$body = preg_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";//Set the character set you need to specify
$mail->IsSMTP(); // Use SMTP service
$mail->SMTPDebug = 1; // Enable debugging for SMTP
// 1 = errors and messages
// 2 = messages only
$mail->From = 'abc#hotmail.com';
$mail->FromName = 'Name';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "SSL";
$mail->Host = 'smtp.live.com';
$mail->Port = '465';
$mail->Username = 'abc#hotmail.com'; //Username of your email account
$mail->Password = '***'; //Password of your email account
$mail->SetFrom('abc#hotmail.com', 'Name');
$mail->AddReplyTo('abc#hotmail.com','Name');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
//var_dump($body);
if(!$mail->Send()) {
//echo $body;
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo "Message sent successfully!";
}
Need help. thanks.
How would I solve this problem? Anyone's help would be appreciated.
Below works for me:
$mail = new PHPMailer();
$mail->SMTPSecure = 'tls';
$mail->Username = "mymail#hotmail.com";
$mail->Password = "mypassword";
$mail->AddAddress("mymail#hotmail.com");
$mail->FromName = "My Name";
$mail->Subject = "My Subject";
$mail->Body = "My Body";
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
$mail->Send();
Windows Live Mail uses port 587(TLS enabled) not the standard 465.
That said wht not just use your hosts local smtp server? That way you won't have to auth (or collect the senders password) and you can still set the senders address as their Hotmail.
$mail->SMTPSecure = "tls";

PHPMailer is not working at all

I'm trying to configure PHPMailer I've uploaded 1 file which is class.phpmailer.php and created another php file with this content:
<?php
require('class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("the same email address");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("the same email address");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
and i get nothing at all not a success message nor a failure message. http://www.mawk3y.net/mailtest/test.php
all answers are outdated now. Most current version (as of Feb 2018) does not have autoload anymore, and PHPMailer should be initialized as follows:
<?php
include_once(FCPATH.'PHPMailer/src/PHPMailer.php');
include_once(FCPATH.'PHPMailer/src/SMTP.php');
include_once(FCPATH.'PHPMailer/src/Exception.php');
$msj="My complete message";
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
//authentication SMTP enabled
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
//indico el puerto que usa Gmail 465 or 587
$mail->Port = 465;
$mail->Username = "xxxxxx";
$mail->Password = "xxxx";
$mail->SetFrom("xxxxxx#xxxxx.com","Name");
$mail->AddReplyTo("xxx#xxx.com","Name Replay");
$mail->Subject = "Test";
$mail->MsgHTML($msj);
$mail->AddAddress("xxxxxx#xxxxx.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
The problem is with the require method.
You first have to extract all file of phpMailer repository.
instead of writing
require('class.phpmailer.php');
you need to include path where your PHPMailerAutoload.php file extracted.so you can replace it with.
require('path-of-extracted-folder/PHPMailerAutoload.php');
for more reference you can visit it's GitHub link
https://github.com/PHPMailer/PHPMailer
I had same problem but I solved.This is the way I code
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
// Set PHPMailer to use the sendmail transport
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc#gmail.com'; // SMTP username
$mail->Password = 'abc'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Set who the message is to be sent from
$mail->setFrom('abc1#gmail.com', 'First Last');
//Set an alternative reply-to address
//Set who the message is to be sent to
$mail->addAddress('abc#gmail.com', 'Shehan');
//Set the subject line
$mail->Subject = 'Test Mail';
$mail->Body = 'This is Test Mail';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

Categories