PHPMailer not working in my server - php

I built a droplet with Ubuntu with DigitalOcean and I'm trying to configure it to send emails with SMTP.
I know DigitalOcean blocks SMTP over IPv6 but not over IPv4 so I disabled IPv6 as this post says.
My script still doesn't work. I've tried with ports 25, 465 and 587. TLS and SSL.
I've installed sendmail for Ubuntu 14.04 but not working.
This is my script:
<?php
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$to = $_GET['email'];
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'rafawins#gmail.com';
$mail->Password = '***';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('rafawins#gmail.com', 'Rafael');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'Subject';
$contents = ob_get_contents();
$mail->Body = "ao!";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
print_r(error_get_last());
?>
The error presented is:
SMTP connect() failed.
I'm interested in sending email using SMTP so ->isSMTP() is required!
Where am I wrong?
Thank you very much.
EDIT:
doing: telnet smtp.gmail.com 587
I get:
Trying 74.125.133.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp
and doing: openssl s_client -connect smtp.gmail.com:465 I get an answer as well...
What's wrong?

Beware of using Gmail from different devices. google doesn't allow and block immediately a location from where an account is used where it isn't supposed to use (in the eyes of google ofcourse).

On live server for send Mail using SMTP, Do it.
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
and Comment $mail->IsSMTP();
It's Working For Me....

Try commenting out line 8.
// $mail->isSMTP();

Related

SMTP connect() failed PHP mailer

I'm trying to send an email from my hotmail account using PHPMailer. It's working fine from my PC but when I try it on another PC I get this error message:
2015-04-23 17:31:18 CLIENT -> SERVER: EHLO localhost
2015-04-23 17:31:18 CLIENT -> SERVER: QUIT
2015-04-23 17:31:18 SMTP connect() failed. Mailer Error
Here's my code:
<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->SMTPSecure = 'SSL';
$mail->Username = "b1sakher#hotmail.fr";
$mail->Password = "rerered";
$mail->AddAddress("b1sakher#hotmail.fr");
$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;
if(!$mail->Send())
{
echo "Mailer Error";
}
else
{
echo "Message has been sent";
}
?>
Firstly you should add 'Debugging Mode' to your code, this will tell you where you are going wrong.
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant
I had a similar issue, but found out it was the CFS Firewall in Cpanel/WHM blocking the port.
Login into WHM.
Go to ConfigServer Security & Firewall inside plugins option.
Click on Firewall configuration.
Filter by SMTP Settings.
Look for SMTP_ALLOWUSER option and add the Cpanel account username separated by coma.
Restart the firewall.
If you don't have access to WHM ask your hosting provider.

How to configure SMTP settings based on web hosting's mail account

Hello how do i configure my php mailer to make it work with these settings?
i tried to fix the username and password but i still get this error
PHPMailer Error: The following From address failed: thesis#thesis.buybranded.com.ph : Called Mail() without being connected
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'gowebph.gowebph.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
// or try these settings (worked on XAMPP and WAMP):
// $mail->Port = 465;
// $mail->SMTPSecure = 'ssl';
$mail->Username = "thesis#thesis.buybranded.com.ph";
$mail->Password = "XXXXXXXXXXXXXX";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
$mail->From = "thesis#thesis.buybranded.com.ph";
$mail->FromName = "Your Name";
$mail->addAddress("vince_agno#live.com","User 1");
$mail->addAddress("2009010067#ust-ics.mygbiz.com","User 2");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
You've got your port & protocol mismatched. port 465 is for ssl and port 587 is for tls.
see https://support.google.com/mail/answer/13287?hl=en
Could you please use this
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
also
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
Or if using TLS try to use port 587 for TLS
from wiki ---Secure SMTP - port 587 (can also use the legacy port 465 - this may solve problems with SSL) (port 587 has optional TLS encryption, possibly using STARTTLS now, or use port 465 for SSL encryption)

phpMailer send a smtp email

I am trying to send an email using phpMailer.
I have downloaded and put the files in "path2".
The php program has 3 inputs: $email, $subject and $body.
Here is the error code when ran:
2014-06-24 15:48:18 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.
Here is my code:
<?php
require_once("..\path2\class.phpmailer.php");
date_default_timezone_set('America/Eastern');
include("..\path2\class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = True;
$mail->SMTPSecure = "SSL";
$mail->Host = "smtp.live.com";
$mail->Port = 465;
$mail->Username = "self#live.com";
$mail->Password = "pass1";
$mail->From="self#live.com";
$mail->Subject = $subject;
$mail->Body=$body;
$mail->AddAddress($email);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Telnet isn't very useful for testing encrypted connections - openssl is better. Try this on your server:
openssl s_client -crlf -connect smtp.live.com:465
That's currently not connecting for me from multiple countries, so perhaps Microsoft finally heeded the deprecation of SSL on port 465 back in 1998... Try this instead:
openssl s_client -starttls smtp -crlf -connect smtp.live.com:587
That's working well for me, so I suggest you make these changes to your code:
$mail->SMTPSecure = "tls";
$mail->Port = 587;

Sending Mail in PHP : SMTP Error: could not authenticate

I am trying to send mail in PHP. I use same code for localhost and server. But when I use the code on server, it doesn't seem to work:
SMTP Error: Could not authenticate. Message was not sent.Mailer error: SMTP Error: Could not authenticate.
Here is my code for your reference.
require("class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myname"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "me#gmail.com";
$mail->AddAddress("sample#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
I've done lots of searching, nothing pops up. Any help would be greatly appreciated.
Try TLS and port 587:
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
As you can see you could also specify that you want SSL connection in the SMTPSecure variable and just use the host as smtp.gmail.com
Also try replacing this $mail->IsSMTP(); with this $mail->Mailer = "smtp";
just check this out it may be helpful:
it's telnet for smtp connection working or not? In windows 7 firewall blocked(default) smtp connection so,
http://support.microsoft.com/kb/153119
Some hosting providers, such as 1and1 block outgoing email ports, such as 25, 465 and 587. The only solution AFAIK is to change hosting provider.
Try making a simple php file that just does a "fsokopen" to the port you are trying to use, and see if that works
It happen because Password contain special character. I tried using "\"before special character like Password="djgh\^dfgfjk". But it didn't help me.
I just create new id and simple password without any special character and amazingly it's work.
Use password with out special character.
It can happen due to various reasons. In my case it worked by changing from
$phpmailer->isSMTP();
to
$phpmailer->Mailer = 'smtp';
worked.

PHP mailer error

I tried to use php mailer but errors as follows.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
and my code
<?php
require("class.phpmailer.php")
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Username = "admin#xxxxxxxxxxxx.in";
$mail->Password = "xxxxxxxx";
$mail->From = "admin#xxxxxxxxxxxx.in";
$mail->FromName = "Mailer";
$mail->AddAddress("xxxx#yahoo.co.in", "mine");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$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. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
I was getting this due to wrong port for SSL.
SSL = 465
TLS = 587
See:
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
Some servers (especially shared hosting) will block you from using SSL with SMTP, I had the same problem once.
Either change host if you can, try using the default PHP mail() function or send through another mail server that does not require SSL e.g. port 25 not 465.
Something like AuthSMTP would be your best bet for an alternate mail server.
I had the same problems, it seems that we have
to set the SMPTSecure value.
First I changed the port from 465 to 587 and added:
$mail->SMTPSecure = "tls";
and it worked :)
If you are working in your localhost just go to the PHP Extention and enable or check the php_openssl
it will be able to access the SSL ports.
try this code
require 'PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "admin#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "admin123";
$mail->setFrom('admin3#gmail.com', 'development'); //add sender email address.
$mail->addAddress('admins#gmail.com', "development"); //Set who the message is to be sent to.
//Set the subject line
$mail->Subject = $response->subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.gif');
//$mail->SMTPAuth = true;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Had the same issue, Change port No in opencart mail setting to 587 and works fine
May be because of fire wall?
If you can't sign in to Google Talk,
or you're receiving an error that
says, Could not authenticate to
server, check if you have personal
firewall software installed, or if
your computer is behind a proxy server
that requires a username and password.
http://www.google.com/support/talk/bin/answer.py?hl=en&answer=30998
I use the same script for several clients and only run into this problem when deploying to Amazon EC2 cloud providers (such as Openshift).
These are tried and tested settings in phpmailer:
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
'but' Google blocks these services as an 'anti-spam' / political maneuver, and this has caught me out because it works locally and on most hosting providers, there is nothing much you can do when they don't accept outbound messages from your hosts DNS / IP. Accept it and move on by looking for another smtp server to route messages through.
not sure but try $mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"

Categories