PHPMailer SMTP ERROR: Failed to connect to server i am hosting this php in easyphp The extension=php_openssl.dll is already uncommended - phpmailer

<?php
$mailto=$_POST['mail_to'];
$mailsub=$_POST['mail_sub'];
$mailtext=$_POST['mail_text'];
require("PHPMailer_5.2.4/PHPMailer_5.2.4/class.phpmailer.php");
require("PHPMailer_5.2.4/PHPMailer_5.2.4/class.smtp.php");
$mail=new PHPMailer(false);
$mail->IsSmtp();
$mail->SMTPDebug=1;
$mail->SMTPAuth=true;
$mail->SMTPSecure="ssl";//smtp protocol
$mail->Host="smtp.gmail.com";
$mail->port=587;//ssl port number
$mail->IsHTML(true);
$mail->Username="myuser#gmail.com";
$mail->Password="mypassword";
$mail->SetFrom("myuser#gmail.com");
$mail->Subject=$mailsub;
$mail->Body=$mailtext;
$mail->AddAddress($mailto);
if(!$mail->Send()){
echo "mail is not sent";
}
else{
echo "mail sent sucess fully";
}
?>
i also changed to tls with port number 587 but it also showing the error i hosting this php in easy php

Related

Sending Email by PHPmailer without SMTP

I know that we could use PHPMailer to send an email without the need of SMTP. But I still don't understand how it is configurated.
1/ Can we set anything to "Email From"? If so then anybody could fake an email address and send it to anybody? If not what is the condition?
2/ What is the basic configuration that a Web server must have in order for it to work.
Sorry for my silly questions.
<?php
$mail = new PHPMailer(true);
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("britney#britneyspears.com", "Britney Spears");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}
?>
I am not familiar.
see. https://github.com/PHPMailer/PHPMailer
1/ Can we set anything to "Email From"?
You can use setFrom . (https://github.com/PHPMailer/PHPMailer#a-simple-example)
$mail->setFrom('from#example.com', 'Mailer');
If so then anybody could fake an email address and send it to anybody?
uhhh... I think SMTP server has error.
PHPMailer use $from. maybe $from was setted by setFrom . (https://github.com/PHPMailer/PHPMailer/blob/master/src/SMTP.php#L817)
If not what is the condition?
If address doesn't set, I think error will occur. (https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L1185)

EOF caught while checking if connected

I would like to send an email from localhost by using PHP Mailer.
i have already look for others question and that solve some of the error that i got.
Except for this last error.i did not find the answer that fit to solve the error. I am really hope for help to solve this error.
This is what being diplayed after try to run the code.
2018-08-03 04:57:44 SERVER -> CLIENT:
2018-08-03 04:57:44 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP Error: Could not authenticate.
Email could not be sent. Mailer Error: SMTP Error: Could not authenticate.
This is my code
<html>
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('test#gmail.com', 'Mailer');
$mail->addAddress('test#gmail.com', 'Naura'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Email testing';
$mail->Body = 'Hi. This is a test email.';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Email has been sent';
} catch (Exception $e) {
echo 'Email could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
</html>

PHP mailer throws error in php 7 when tried send mail

I'm trying to send mail using PHP Mailer but I'm getting an error.
Kindly check my code let me know the fix.
Here is my code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer;
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxxxxxxx ';
$mail->Password = 'xxxxxxxxx';
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('xxxxxxx', 'shiva');
$mail->addAddress('siva.sing.sivan#gmail.com', 'SP'); // Add a recipient
$mail->addAddress('senthil.mca2008#gmail.com', 'SK'); // Add a recipient
//\\$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('opensourcesivaprakash#gmail.com', 'Information');
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test mail form SP';
$mail->Body = 'This is the HTML message <b>From SP!</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;
exit;
}else{
echo 'Message has been sent';
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
My Error:
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Please correct my code to fix the issue.
Hey #shiva use this $mail->SMTPSecure = 'tls' and use port as $mail->Port = 587 that's it!
Tell me it worked for you, if not then make sure to enable "Less Secure Apps" in your account settings, Thanks!
Let me know it worked for you or not?
upgrade the php version to 7.2.x and try it has inbuilt openssl 1.1.1

PHPMailer + smtp.gmail.com : Could not connect to SMTP host

I was trying to use PHPMailer library to send email.
I installed PHPMailer using composer And i just use their tutorial example.
Before that I also set the gmail account settings to allow less secure apps.
Here is my code:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'phpmailer/vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com:587'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'hidden#gmail.com'; // SMTP username
$mail->Password = 'hidden'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('hidden#gmail.com', 'Mr. From');
$mail->addAddress('to.#gmail.com', 'Mr. To'); // Add a recipient
//Content
$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';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
And Here is the Error:
2018-03-30 05:44:49 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 5sm16638786pfh.133 - gsmtp
2018-03-30 05:44:49 CLIENT -> SERVER: EHLO localhost
2018-03-30 05:44:50 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [123.244.104.122]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-03-30 05:44:50 CLIENT -> SERVER: STARTTLS
2018-03-30 05:44:50 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2018-03-30 05:44:50 CLIENT -> SERVER: QUIT
2018-03-30 05:44:50
2018-03-30 05:44:50
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
Please help me.
Just Add the following codes before line code $mail->SMTPDebug saves the day
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);

how to send mail using phpmailer with smtp.office365.com

I am using below code to send mail but this is not working for me. Please help me to resolve this problem.
require 'class.phpmailer.php';
require 'class.smtp.php';
$subject="Test PHP mailer";
$message="Hi";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier - TLS/SSL
$mail->Host = "smtp.office365.com"; // sets GMAIL as the SMTP server - smtp.gmail.com
$mail->Port = 587; // set the SMTP port for the GMAIL server - Gmail SMTP port (SSL): 465 **** Gmail SMTP port (TLS): 587
$mail->Username = ""; // other email address
$mail->Password = ""; // password
$mail->SetFrom("customercare#test.com", "John");
$mail->addReplyTo('customercare#test.com', 'John');
$mail->Subject = $subject;
//$mail->IsHTML(true);
$mail->MsgHTML($message);
$mail->AddAddress('abc#example.com');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
It display error message:
Mailer Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: 5.7.60 SMTP; Client does not have permissions to send as this sender SMTP code: 550
Looking at the error message, it's not a problem with the code, but a problem with the permissions for the user your are trying to send as.
You will either need to get the user you're trying to send as to allow their account to be used in such a way, or you'll have to find a different smtp service to use.

Resources