SMTP ERROR Failed to connect to server A connection attempt failed - php

I have a problem sending an email and this is the error:
Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (A connection attempt failed because the connected party did not respond properly after a period of time, or established connection failed because connected host has failed to respond.)
SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not respond properly after a period of time, or the established connection failed because the connected host failed to respond. (10060)
I've adjusted the one on https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting and it's still an error, can someone help me please?
public function Approve1($id)
{
// For database
$data = $this->ApprovalModel->requisition_approval(array('hod'=>'submit'),$id);
if($this->db->affected_rows() > 0)
// PHPMailer object
$id=$this->uri->segment(3);
$email=$this->uri->segment(4);
$response = false;
$mail = new PHPMailer();
// SMTP configuration
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPDebug = 3;
$mail->SMTPAuth = true;
$mail->Username = 'xyz#gmail.com';
$mail->Password = 'xyz';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('xyz#gmail.com', 'xxx');
$mail->addAddress($email);
$mail->Subject = 'hii!';
$mail->isHTML(true);
// Email body content
$loginlink = site_url() . 'login' . '"';
$mailContent = <<<HEREDOC
Dear Sir/Madam ,
Your staff asked for Manpower Request, please click this link for your approval $loginlink
<p>Thank you,</p>
<p>Cladtek HRIS</p>
HEREDOC;
$mail->Body = $mailContent;
// Send email
if(!$mail->send()){
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else{
$this->session->set_flashdata('flash', '<div class="alert alert-success" role="alert"> Submit Succesfully!<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div>');
return redirect('home/manage_data');
}
}

Related

Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)

I'm trying to use PHPMailer but I'm getting the following error:
Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)
Here is my code:
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // 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 = 'test#gmail.com'; // SMTP username
$mail->Password = 'some_password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('earndreamsol#gmail.com' );
$mail->addAddress($email); // Add a recipient
//$mail->addReplyTo($email, $name);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Email from Alahmed & Co";
$mail->Body = " Thanks For Subscribe Alahamed & co";
$mail->AltBody = "Thanks For Subscribe Alahamed & co";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$_SESSION['msg']="you are successfully subscribed !!";
$_SESSION['msg1']="you are successfully subscribed !!";
header("location:index.php#newssection");
}
Have you try to use :
$mail->SMTPSecure = 'tls';
and/or :
$mail->Port = 587;

PhpMailer error : Message could not be sent.Mailer Error: SMTP connect() failed

I search google and this site and can't fix this phpMailer error and that's why I need you help.
I am sending email using following phpMailer code but all time it's showing me error message :
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
PhpMailer Code
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = gethostbyname("smtp.gmail.com");
$mail->SMTPAuth = true;
$mail->Username = 'hello#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML(true);
$mail->Priority = 1;
$to = 'to#gmail.com';
$mail->setFrom('support#site.com', 'Sitename');
// Send Email tto user ####################################
$mail->addAddress('some#gmail.com', 'Shibbir Ahmed');
// send email to admin #####################################
$mail->addReplyTo('some#gmail.com', 'Information');
$mail->Subject = 'Test Subject';
$get_templae = mysqli_query($conn, "SELECT * FROM email_template WHERE t_id = '8' ");
$get_restult = mysqli_fetch_array($get_templae);
$template = $get_restult['t_content'];
$mail->Body = $template;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Can you please tell what I am doing wrong in this code ?
I am getting this error :
2016-04-21 15:19:51 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-21 15:19:51 SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Update :
Current Error from my server :
2016-04-21 18:06:01 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-21 18:06:01 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting bool(false)
Try to lower your gmail security, for the SMTP!
Link: https://www.google.com/settings/security/lesssecureapps
And add de debuginfo property to see more what is wrong.
$mail->SMTPDebug = 1;
you can change the value to 1 2 3 or 4 to ingress the filtering form debuginfo.
Hope this helps you out ;)
The best ways to debug PHPMailer errors is to uncomment
$mail->SMTPDebug = 3;
It will give you a detailed log of the events happening. From authentication all the way to where the request is successful or fails
Step1: Go to Gmail setting and enable IMAP.
Step2: Clear your browser cache and check it.
If issue still persists lower your Gmail security by using "settings" tab.
Gmail Security alert will be like this

using phpmailer with google apps

can anyone help me figure out what the problem is here. I've done lots of searches and have done what I've found to no success.
here is my error, phpmailer is newest version
2015-08-08 13:15:03 Connection: opening to ssl://smtp.mysite.com:465, timeout=300, options=array ( ) 2015-08-08 13:15:04 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-08-08 13:15:04 SMTP connect() failed.
here is my code.
$m = new PHPMailer;
//Setup
$m->isSMTP();
$m->SMTPAuth = true;
//authentication
$m->Host = 'smtp.gmail.com';
$m->Username = 'info#example.com';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->SMTPDebug = 3;
//from
$m->AddReplyTo($email, $name);
$m->SetFrom('info#example.com', $name);
//to
$m->addAddress('ari#example.com','guy johnson');
$m->addCC('joe#example.com','Joe johnson');
//message
$m->Subject = $subject;
$m->Body = $message;
if(!$m->Send()) {
echo"<script type=\"text/javascript\">".
"alert('A Error Occured, Please Try Again.');".
"</script>";
} else {
echo"<script type=\"text/javascript\">".
"alert('Message Sent. Please allow atleast 24-hours for a response');".
"window.location='http://example.com';".
"</script>";
}
thanks in advance!
Your error message shows smtp.example.com in the error but your code shows smtp.gmail.com. Have you tried port 25? The Google documentation suggests trying that with SSL.

Called Mail() without being connected while sending email using phpmailer

I am trying to send mail using phpmailer but it is giving error
<?php
include("/mail/class.phpmailer.php");
// Basic Header Input
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Username = 'username'; // your GMail user name
$mail->Password = 'password'; //"Password";
// ---------- adjust these lines ---------------------------------------
$mail->From= 'mg#gmail.com';
$mail->FromName="My site's mailer";
$mail->AddAddress("mg123#gmail.com");
$mail->Subject = "Your invoice";
$mail->IsHTML(false);
$mail->AddAttachment('test1.pdf', 'invoice.pdf'); // attach files/invoice-user-1234.pdf, and rename it to invoice.pdf
$mail->Body = "Please find your invoice attached.";
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
echo "Letter is sent";
}
?>
it is showing error like Error sending:
"Error sending: The following From address failed:
mg#gmail.com : Called Mail() without being connected"
i try with adding code $mail->SMTPDebug = 1; then it is showing error like below
SMTP -> ERROR: Failed to connect to server:
php_network_getaddresses: getaddrinfo failed: No such host is known.
(0) The following From address failed: mg#gmail.com
: Called Mail() without being connected
Change this,
$mail->From= 'mg#gmail.com';
You are mixing single quotes and double quotes

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!

Categories