Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message could not be sent.Mailer Error: SMTP connect() failed. #469

Closed
rocky5469 opened this issue Aug 3, 2015 · 35 comments
Closed

Message could not be sent.Mailer Error: SMTP connect() failed. #469

rocky5469 opened this issue Aug 3, 2015 · 35 comments

Comments

@rocky5469
Copy link

hi, i'm new to php and i have been trying to send e-mail through php, phpmailer is the only class i find most recommended by most of the developers. i tried almost all solutions for my error. i cant find the fix. I have tried the link below, but didn't get what to do, and googled for the solution, couldn't find any, which works for me. tried almost all solutions, but it keeps showing me the same error.

Message could not be sent.Mailer Error:SMTP connect() failed.https://github.com/PHPMailer/PHPMailer/wiki/TroubleshootingAvailable

tried the above link, as im new to php, im stuck.

fr all smtpdebug: 1,2,3,4, its giving same error... but php mail() function is working fine.

and our hosting provider says this...

We have the following list of ports open on our shared hosting plans:

HTTP/HTTPS - 80/443
GMail - 465/587/995/993
TOMCAT - 8080
SMTP/IMAP/POP - 25/143/110

here is the code im using. please help me to resolve the error. thanx in advance.

<?php


require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';              // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = [email protected]';
$mail->FromName = 'Mailer';
//$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>
@Synchro
Copy link
Member

Synchro commented Aug 3, 2015

That link should be https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting - I'm not sure where the "Available" came from. As the guide says, in pretty much every case this is nothing to do with PHPMailer, but the network config on your server or ISP. Setting SMTPDebug to anything higher than 0 should produce visible output, which you have not posted here. Most of the tests described in the guide require you to SSH into your server and run the commands from there.

The mail function may appear to work, but it's not doing the same thing - it's sending through your local mail server, not your Gmail account. You can do the same thing with PHPMailer by calling isMail instead of isSMTP.

@rocky5469
Copy link
Author

thank you so much Synchro for your precious feedback .

isMail() working perfectly. but i dnt knw y isSMTP is still giving some error, which i dont understand at all
ERROR is:

2015-08-04 01:59:54 CLIENT -> SERVER: EHLO mysite.com
2015-08-04 01:59:54 CLIENT -> SERVER: AUTH LOGIN
2015-08-04 01:59:54 CLIENT -> SERVER: cm9ja3k1NDY5QGdtYWlsLmNvbQ==
2015-08-04 01:59:55 CLIENT -> SERVER: KioqKioqKioqKioqKioq
2015-08-04 01:59:55 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257 <b>i7sm8522522obe.8</b> - gsmtp
2015-08-04 01:59:55 SMTP Error: Could not authenticate.
2015-08-04 01:59:55 CLIENT -> SERVER: QUIT 2015-08-04 01:59:55 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/TroubleshootingAvailable

My coding

<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';              // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = [email protected]';
$mail->FromName = 'Mailer';
//$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

@rocky5469
Copy link
Author

Synchro sorry, i didnt mentioned that the bold values in error message, keeps on changing each time i refresh my page...

@Synchro
Copy link
Member

Synchro commented Aug 4, 2015

That bold value is just a link tracking ID, it will end up in the same place. So it just looks like your username or password is not correct.

@Synchro
Copy link
Member

Synchro commented Aug 4, 2015

That transcript looks like you have SMTPDebug = 1; try setting it to 2 and you should see more info.

@rocky5469
Copy link
Author

dear synchro. thanks for your reply. but got some issues.

<?php
require 'phpmailer/PHPMailerAutoload.php';


$mail = new PHPMailer;

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$file = $_FILES['attachment']['tmp_name'];

$message = $_POST['message'];

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isMail();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = $name;
//$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'SASP Contact Form';
$mail->Body = $message;
$mail->Body .= "<br /><br />Below are my contact details <br /> Name: ";
$mail->Body .= $name;
$mail->Body .= "<br />My Phone number: ";
$mail->Body .= $phone;
$mail->Body .= "<br /> My email address: ";
$mail->Body .= $email;


$mail->AltBody = 'You are using basic web browser ';
if(is_array($_FILES)) {
    $mail->AddAttachment($_FILES['attachment']['tmp_name'],$_FILES['attachment']['name']); 
}

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    //echo 'Message has been sent';
    header('Location: thankyou.html');
}
?>
  1. in the above code, when i send mail from isMail() function, its working perfectly wen the recipient mail is [email protected]. but if i change the recipient mail to, [email protected], its shows. following error...

Message could not be sent.Mailer Error: Could not instantiate mail function.

@Synchro
Copy link
Member

Synchro commented Aug 7, 2015

Solve one problem at a time. Your code for handling attachments is wrong - look at the examples folder for how to do that properly, but solve your connection problem first.
If you're getting messages like that using isMail(), look in your mail server log and check your PHP config.

@rocky5469
Copy link
Author

thank u fr the replay..
but i'm clueless what i need to check in php config..?
i m using shared hosting..

@Synchro
Copy link
Member

Synchro commented Aug 7, 2015

"Could not instantiate mail function" usually means you have no local mail server, so check that you have one. In your php.ini file you should have a setting for sendmail_path, and that program must exist. If you can't change that, or it doesn't exist, contact your hosting provider.

When you say "it's working perfectly", do you mean that the script runs and you receive the sent message?

@rocky5469
Copy link
Author

yes. when i use isMail(). i receive message perfectly. only when the recipient mail is [email protected]

but when i change the $mail->addAddress('[email protected]'); to $mail->addAddress('[email protected]');.

with rest of the code untouched, i get "Could not instantiate mail function"

@Synchro Synchro closed this as completed Sep 2, 2015
@Synchro
Copy link
Member

Synchro commented Sep 30, 2015

How about you read the docs the error message links you to?

On 30 Sep 2015, at 12:16, shivka [email protected] wrote:

hello synchro....
I have an error in my coding
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

IsSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = '[email protected] mailto:[email protected]'; $mail->Password = '1234567890'; $mail->SMTPSecure = 'tls'; $mail->Port=587; $mail->From = '[email protected] mailto:[email protected]'; $mail->FromName = 'sonam'; $mail->addAddress('[email protected] mailto:[email protected]', 'shanu'); $mail->addReplyTo('sonamsingh.covetus@gmail', 'shanu'); $mail->WordWrap = 50; $mail->isHTML(true); $mail->Subject = 'Using PHPMailer'; $mail->Body = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo 'Message has been sent'; /*require 'PHPMailer-master/PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = '[email protected] mailto:[email protected]'; $mail->Password = 'job2015@'; $mail->SMTPSecure = 'ssl'; $mail->Port=465; $mail->SMTPDebug = 3; $mail->From = '[email protected] mailto:[email protected]'; $mail->FromName = 'sonam singh'; $mail->addAddress('[email protected] mailto:[email protected]'); $mail->addReplyTo('[email protected] mailto:[email protected]', 'sonam singh'); $mail->WordWrap = 50; $mail->isHTML(true); $mail->Subject = 'Using PHPMailer'; $mail->Body = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo 'Message has been sent'; */ ?>


Reply to this email directly or view it on GitHub #469 (comment).

@shivka
Copy link

shivka commented Sep 30, 2015

its show on my page

@shivka
Copy link

shivka commented Sep 30, 2015

how can i solve my error


Reply to this email directly or view it on GitHub
#469 (comment)
.

@Synchro
Copy link
Member

Synchro commented Sep 30, 2015

Read the docs, like I told you.

On 30 Sep 2015, at 12:36, shivka [email protected] wrote:

how can i solve my error


Reply to this email directly or view it on GitHub
#469 (comment)
.


Reply to this email directly or view it on GitHub #469 (comment).

@Mozammelctgmirbd
Copy link

Dear brother(synchro)
assalamualaikum.i got successfully messase(when i run form localhost).but i dont get message when i open my gmail account([email protected]).

@Mozammelctgmirbd
Copy link

this is my code

<?php
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer;

$name = 'name';
$phone = 'phone';
$email = 'email';
$message = 'HI Friends How are you';

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isMail();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = '*****';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 486;                                    // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = $name;
//$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'SASP Contact Form';
$mail->Body = $message;
$mail->Body .= "<br /><br />Below are my contact details <br /> Name: ";
$mail->Body .= $name;
$mail->Body .= "<br />My Phone number: ";
$mail->Body .= $phone;
$mail->Body .= "<br /> My email address: ";
$mail->Body .= $email;


$mail->AltBody = 'You are using basic web browser ';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';

}
?>

@Synchro
Copy link
Member

Synchro commented Dec 27, 2015

@Mozammelctgmirbd: Read before posting, don't hijack old threads. You are using an old version of PHPMailer and have not read the docs. You've made up apparently random settings and you're wondering why it doesn't work. It's very likely that you need to say $mail->Port = 465;.

@Mozammelctgmirbd
Copy link

Dear Brother
which mail address i will get message. i am Confucius.i am not getting message in [email protected] and [email protected].
but i am getting echo 'Message has been sent'

@Mozammelctgmirbd
Copy link

sendmail.inc i change flowing this

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
auth_username=[email protected]
auth_password=

@Mozammelctgmirbd
Copy link

you told me that for change $mail->Port = 465;.
i change this
but
i am not getting message in [email protected] and [email protected].
but i am getting echo 'Message has been sent'

@Mozammelctgmirbd
Copy link

i dont undestand.please help me

@Synchro
Copy link
Member

Synchro commented Dec 27, 2015

Sendmail settings have no effect because you're using SMTP - again, changing random settings will not help. Messages will be sent to your gmail address, but you really need to read the docs.

@Mozammelctgmirbd
Copy link

Dear Brother
i forget before code of sendmail.inc
sendmail.inc i change flowing this
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
auth_username=[email protected]
auth_password=

@Synchro
Copy link
Member

Synchro commented Dec 27, 2015

There's not much point in me trying to help you if you don't read what I say. Also, don't post your passwords - this is a public forum.

@Mozammelctgmirbd
Copy link

sorry my dear Brother

@Mozammelctgmirbd
Copy link

you are helper so that i know about you

@Mozammelctgmirbd
Copy link

Dear Brother
again insttal xampp.try again but dont get any message i sing in [email protected]
this my code

SMTPDebug = 3; // Enable verbose debug output $mail->isMail(); // Set mailer to use SMTP $mail->Host = 'localhost'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = '*****'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, ssl also accepted $mail->Port = 465; // TCP port to connect to $mail->From = '[email protected]'; $mail->FromName = $name; //$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient $mail->addAddress('[email protected]'); // Name is optional //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'SASP Contact Form'; $mail->Body = $message; $mail->Body .= " Below are my contact details Name: "; $mail->Body .= $name; $mail->Body .= " My Phone number: "; $mail->Body .= $phone; $mail->Body .= " My email address: "; $mail->Body .= $email; $mail->AltBody = 'You are using basic web browser '; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?>

@Mozammelctgmirbd
Copy link

please help me

@Mozammelctgmirbd
Copy link

Dear broth (Synchro)
what can i do.

@Synchro
Copy link
Member

Synchro commented Dec 28, 2015

I don't know how I can make this any clearer: read the docs.

@Mozammelctgmirbd
Copy link

ok dear you say i want to see message. which mail this message will be store

@Mozammelctgmirbd
Copy link

[email protected] or [email protected] ------------------which--????

@Mozammelctgmirbd
Copy link

please please please
i use this code localy
lan local area network

@Mozammelctgmirbd
Copy link

not online from any site

@Synchro
Copy link
Member

Synchro commented Dec 28, 2015

It will send to [email protected], from [email protected]. I can't help you if you won't do what I suggest. It sounds like you really don't know what you're doing, so read the docs not only for PHPMailer, but for PHP as well. I am not here to teach you PHP - there are many other places you can learn that.

@PHPMailer PHPMailer locked and limited conversation to collaborators Dec 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants