/    Sign up×
Community /Pin to ProfileBookmark

Getting Connection and Authentication errors while sending mail using PHPMailer

Hi All,

I wanted to send mail in php and as i do not have any mail server at home so i googled for free smtp server which i can configure and use in PHP.

I am facing problem in sending a mail using PHPMailer.

I wanted to verify the mail functionality before giving to somebody else for execution.

Below I am providing the environment details where the PHP is installed in my local system.

I am using laptop with internet connection(via data card).

OS:- Windows 7
Web Server:- IIS 7
PHP Ver:- 5.6.0

Below is the smtp configuration in
php.ini and also extension=php_openssl.dll is uncommented in php.ini file:-

[mail function]
; For Win32 only.
; [url]http://php.net/smtp[/url]
SMTP = localhost
; [url]http://php.net/smtp-port[/url]
smtp_port = 25

; For Win32 only.
; [url]http://php.net/sendmail-from[/url]
;sendmail_from = [email][email protected][/email]

[ExtensionList]
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_imap.dll
extension=php_tidy.dll

Mail Functionality

PHPMailerAutoload.php
class.phpmailer.php
class.pop3.php
class.smtp.php

All the above files are in the same directory where email.php(shown at below) is there.

File Name:- [url]http://localhost/PHPMail/email.php[/url]

<?php

require(“PHPMailerAutoload.php”);

$email = “[email protected]” ;
$message = “This is the mail from PHPMailer.” ;
$mail = new PHPMailer();

// set mailer to use SMTP
$mail->IsSMTP();
$mail->SMTPDebug = 1;

// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = “ssl://smtp.gmail.com”; // specify main and backup server

$mail->Port = 465;//port

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = ‘SSL’; // secure transfer enabled REQUIRED for GMail

// When sending email using PHPMailer, you need to send from a valid email address
// In this case, we setup a test email account with the following credentials:
// email: [email][email protected][/email]
// pass: password
$mail->Username = “[email protected]“; // SMTP username
$mail->Password = “********”; // SMTP password

// $email is the user’s email address the specified
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST[’email’] ;
$mail->From = $email;

// below we want to set the email address we will be sending our email to.
$mail->AddAddress(“[email protected]“, “Gopal Krishna”);

// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = “You have received feedback from your website!”;

$mail->Body = $message;

if(!$mail->Send())
{
echo “Message could not be sent. <p>”;
echo “Mailer Error: ” . $mail->ErrorInfo;
exit;
}

echo “Message has been sent”;
?>

I am getting the error messages for different SMTP Host and port configurations.

1.
$mail->Host = “ssl://smtp.gmail.com”;
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘SSL’;

Error Message:-

SMTP -> ERROR: Failed to connect to server: (0)
SMTP Error: Could not connect to SMTP host. Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.

2.

$mail->Host = “smtp.gmail.com”;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘TLS’;

Error Message:-

SMTP -> ERROR: AUTH not accepted from server: 530 5.7.0 Must issue a STARTTLS command first. 2sm15315794pdp.68 – gsmtp
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.

3.
$mail->Host = “smtpout.secureserver.net”;
$mail->Port = 80;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ”;

SMTP -> ERROR: Password not accepted from server: 535 Authentication Failed for [email][email protected][/email]
SMTP -> ERROR: RSET failed:
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
SMTP server error:

Kindly assist me in resolving this issue.

Thanks & Regards,
[email][email protected][/email]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulAug 10.2015 — Hi and welcome tto the site. I've never set up a mail server, but this line seems questionable:

$mail->SMTPSecure = '';

Is that " two ' (apostrophes) or one " (double quote)?

Also, why are you using different SMTP hosts? If you are not authorised to use these hosts, presumably they will fail!
×

Success!

Help @gkrishnat2015 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...