SMTP connection error in php mail - php

<?php
require '/etc/PHPMailer/PHPMailerAutoload.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 = "my#gmail.com";
$mail->Password = "password";
$mail->SetFrom("from#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("to#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
This is my mail functionality code & it gives me the error
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No address associated with hostname
I don't have extension=php_openssl.dll in my php.ini file but still I've included this and the same issue

To avoid the problem of dynamic IP (every time i ping smtp.gmail.com I see a slight difference in the last 3digit chunk), you just have to use php built-in gethostbyname() to read the IP in real-time.
$smtp_host_ip = gethostbyname('smtp.gmail.com');
Then use that as host.
Hope it helps.

Related

PHP mailer error in xampp local server

Trying to send email through PHP mailer from local xampp but getting error:
SMTP -> ERROR: Password not accepted from server: 535-5.7.8 Username and Password not accepted.
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required.
The following From address failed: azadlm460#gmail.com : MAIL not accepted from server,530,5.5.1
Code is:
<?php
function sendOTP($clientemail,$num) {
require('phpmailer/class.phpmailer.php');
$message_body = "One Time Password for PHP login authentication is:<br/><br/>" . $num;
$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 = "Azad";
$mail->Password = "mypass";
$mail->SetFrom("myemail");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("anotheremail");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
}
?>
Already tried:
Added PHP mailer in root.
Allow access for less secure apps.
Changed password for gmail.
Account access enabled.

PHP Mailer can't send emails using my work internet connection

i'm developing a website to send reminders to employees in my company using phpmailer, the emails are working fine, but when i connect to the workplace internet connection it stops working with no errors but:
Connection: opening to smtp.mail.yahoo.com:587, timeout=300, options=array ( )
i'm guessing it might be a closed port, so i tried using 587 and 25.
i'm not that good in networking, is there's any way i can know what is the exact error?
function SendOutlook(){
//$recipient = 'xxxxx#yahoo.com';
require 'PHPMailer/PHPMailerAutoload.php';
$Emp_recipient = "employee#yahoo.com";
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "smtp.mail.yahoo.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxx#yahoo.com'; // SMTP username (server username)
$mail->Password = 'xxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('xxxxx#yahoo.com', 'One');
$mail->addAddress($Emp_recipient,"name"); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'test';
$mail->Body = "scheduled on your outlook calender";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit();
}else {
echo '<p>Message has been sent</p>';
}
echo !extension_loaded('openssl')?"Not Available":"Available";
}

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);

Not able to use phpmailer script for gmail

This is my php script:
<?php
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already
$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 = "x#gmail.com";
$mail->Password = "1234";
$mail->From = "y#gmail.com";
$mail->Subject = "Need Invitation";
$mail->Body = "invite me!";
$mail->AddAddress("x#gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
After executing this script i am getting following error:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1)
I have also ssl enabled:
There are a lot of question which are very similar to this but didn't get any help from there.
Try changing
$mail->Host = "ssl://smtp.gmail.com";
to
$mail->Host = "smtp.gmail.com";
SSL operates at a different level in the network model from HTTP, SMTP, etc.
You may also have to change your SMTPSecure setting from 'ssl' to 'tls'.

SMTP Gmail Server SSL Error

I used this coding to send mail using gmail, but am getting the below error, here when i removed the ssl part, its working, but i dint receive any emails(checked inside spam also). Any other problems ?
$mail = new phpmailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1;// enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "un"; // GMAIL username
$mail->Password = "pwd"; // GMAIL password
$mail->SetFrom('test#gmail.com', 'Bharanidharan');
$mail->AddReplyTo("test#gmail.com","Vishal Kumar");
$mail->AddAddress("test#gmail.com","Bharani");
$mail->Subject = "Hey, check out";
$body = "hey, check email";
$mail->MsgHTML($body);
$address = "test#gmail.com";
$mail->AddAddress($address, "test");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
Enable the mod_ssl in Apache (search the config file) and the openssl PHP extension (check php.ini)

Categories