SMTP connect() failed. PHPMailer (GMAIL) [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hello i create code for send to email using php mailer in localhost
but i have a problem, this error is : Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
This is my code
<?php
require_once('mailer/class.phpmailer.php');
require_once('mailer/PHPMailerAutoload.php');
$from_email = "gumay0838#gmail.com";
$from_email_pwd = "qwerty147";
$from_email_name = "Gumay";
$to_email = "bedhoel.inc#gmail.com";
$mail = new PHPMailer();
$body = 'Hello World';
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = $from_email; // GMAIL username
$mail->Password = $from_email_pwd; // GMAIL password
$mail->SetFrom($from_email, $from_email_name);
$mail->Subject = "Testing Mail";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress($to_email, $from_email);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Note :
im already active
extension=php_openssl.dll in php.ini
and already restart my xampp and already setting my gmail to Allow less secure apps: ON

Related

The email wont sent to gmaill on php [duplicate]

This question already has answers here:
SMTP connect() failed PHPmailer - PHP
(17 answers)
Closed 4 years ago.
I'm a beginner in php so I had written code for testing which will send an email using php.
I'm using "PHPMailer-5.2.27" to sent email with SMTP on php, but when I run the code the email not sent. I don't know what is the problem. Can anyone help me out!
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->Host = "smtp.gmail.com";
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = "example#gmail.com";
$mail->Password = "xxxxxxxx";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Subject = "test mail";
$mail->Body = "just a test";
$mail->setFrom('example#gmail.com','aaaa');
$mail->addAddress('example#gmail.com');
if ($mail->send())
echo "mail is sent";
else
echo "something wrong ";
?>
Assuming you have allowed your Gmail account to authorize the server from where you are sending an email.
use $mail->ErrorInfo; in order to debug your issue, this will clarify what is the actual failure reason for sending an email you can refer the below code I have shared.
<?php
require "PHPMailer/PHPMailerAutoload.php";
echo !extension_loaded('openssl')?"Not Available":"Available"; //check openssl is available or not
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // 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 = "mygmailaccount#gmail.com";
$mail->Password = "**********";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("toaddress#gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>

user name and email address not received by PhpMailer [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Sender email and name was not received.
PhpMailer message says email was successfully sent, but I cant get the sender email or sender name. I received only the body and subject.
Thanks
<?php
require 'PHPMailerAutoload.php';
$name = $_POST['fname'];
$mail = $_POST['email'];
$subject = $_POST['subj'];
$message = $_POST['mssg'];
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'xxxxhost.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxx#host.com'; // SMTP username
$mail->Password = 'xxxxxxxxxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom($mail, $name); // this value not received
// Add a recipient
$mail->addAddress('support#example.com'); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
You question isn't very clear, but I'll take a guess at what you're asking.
Don't use the submitter's email address as the From address. It's forgery and will usually mean you get rejected for SPF violations or end up in spam folders. Gmail doesn't let you use arbitrary from addresses for this reason (though you can predefine aliases in gmail prefs) and it will simply use your Username address instead.
Set the submitter's address as a reply-to (see addReplyTo() in PHPMailer) and your own address as the from address. This way you won't be forging anything, and replies will go to the right place. Like this:
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->setFrom('me#example.com', 'My Name');
It's a good idea to put those values into the message body as well in case it's an invalid email address due to a simple typo, for example user #example.com. The reply-to will not work, but you'll still have the data.
If you are trying from Gmail server, try this (without tls encryption):
$mail->Host = "mail.xxxhost.com";
$mail->Port = 26;
OR (with tls encryption):
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
May be you need to correct in your code
$mail->host = "mail.xxxhost.com";
from
$mail->host = 'xxxhost.com';

PHPMailer - authentication problems [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Im trying to create an email service with PHPMailer and im receiving and authentication error and the username and password are correct .
This is my code:
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = “myemail#gmail.com";
$mail->Password = “my gmail password”;
//Set who the message is to be sent from
$mail->setFrom(‘example#gmail.com', 'Nicolas El Mir');
//Set who the message is to be sent to
$mail->addAddress('example#gmail.com', 'Nicolas Mir');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->Body = 'This is a plain-text message body';
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Thanks for your help !
Your problem starts here:
$mail->Username = “myemail#gmail.com";
$mail->Password = “my gmail password”;
//Set who the message is to be sent from
$mail->setFrom(‘example#gmail.com', 'Nicolas El Mir');
You see those curly/smart quotes? “ ” ‘
“myemail...
“my gmail password”
‘example...
They're choking your script.
$mail->Username = "myemail#gmail.com";
$mail->Password = "my gmail password";
//Set who the message is to be sent from
$mail->setFrom('example#gmail.com', 'Nicolas El Mir');
Had you error reporting set to catch/display, it would have told you about it.
http://php.net/manual/en/function.error-reporting.php
I'm really hoping that is your actual code too, rather than just a bad Word Processor paste.
Plus, make sure you do have a Webserver/PHP installed and that mail is enabled on it.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Plus, pulled from this answer https://stackoverflow.com/a/16048485/ which may be the same problem for you, the port number, etc.
$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 = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
This code above has been tested and worked for me.
It could be that you needed $mail->SMTPSecure = 'ssl';
Also make sure you don't have two step verification switched on for that account as that can cause problems also.
UPDATED
You could try changing $mail->SMTP to:
$mail->SMTPSecure = 'tls';
It's worth noting that some SMTP servers block connections.
Some SMTP servers don't support SSL (or TLS) connections.
and pulled from another answer https://stackoverflow.com/a/31194724/ in that question:
The solution was that I had to remove this line:
$mail->isSMTP();
I think it comes from your gmail account. Your account doesn't allow less secure apps. You can turn it on through this link Google security sttings
Try this copy libeay32.dll and ssleay32.dll to windows/system2. These two files you will find in php folder (main folder). With this you can enable php extensions. i.e curl etc. If this doesn't work, mention your error message. or check out some youtube videos! That would be suitable. Thank you.

PHPmailer dont send the email [duplicate]

This question already has answers here:
"SMTP Error: Could not authenticate" in PHPMailer
(21 answers)
Closed 8 years ago.
I receive this error: SMTP Error: Could not authenticate.
This is the code, i think that everything is ok, the password is ok, the emails are ok, ist in localhost,...
<?php
require './class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "email#gmail.com";
$mail->Password = "*********";
$mail->SetFrom('email#gmail.com', 'user');
$mail->AddAddress('email2#gmail.com', 'user');
$mail->Subject = 'this is a text email';
$mail->MsgHTML('content');
$mail->AltBody = 'This is a plain-text message body';
if(!$mail->Send()) {
echo "Error: " . $mail->ErrorInfo;
} else {
echo "Send!";
}
?>
Set SMTPDebug to 2 and see what you get but it seems like you're connecting and quite literally not able to authenticate with google's smtp server, if so your username or password is indeed wrong or being blocked (sometimes gmail will block logins from connections it's never seen before until you login and assure it everything's fine).

Php SMTP mail Issue

I got a project which I need to create a personal web site but I can not send e mail via contact form. Could you pls assist me what do I need to do in order to fix it.
I have added class.phpmailer.php and class.smtp.php. Here is php code;
<? php
include '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 = "behzatdeniz82#gmail.com";
$mail->Password = "myseccretpassword"; //Don't reveal password with others
$mail->SetFrom("behzatdeniz82#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("behzatdeniz99#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
After I change the php code as above, now I begin to receive this error. Can anyone help me how to fix ?
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl"
- did you forget to enable it when you configured PHP? (1702478359)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error:
Could not connect to SMTP host.
It seems like SetFrom method is missing. There are multiple versions of PHPMailer available. Download PHPMailer 5.1 which contains a setFrom method:
public function SetFrom($address, $name = '',$auto=1) {
Just Try.
just a small bug, which may be the solution: a missing ' here, after My Name, $mail->SetFrom($mail->Username, 'My Name);

Categories