Extension missing: openssl Mailer Error: Extension missing: openssl - php

I am using php mailer to generate mails but the code works fine on local machine but when i uploaded the same on my server its giving this error (Extension missing: openssl Mailer Error: Extension missing: openssl), I have opened 587 port as well, Still its not working
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'abc#gmail.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls'; // Even ssl is not working
//$mail->Port = 587;
$mail->setFrom('abc#gmail.com', 'abc');
$mail->addAddress('def#yahoo.com', 'DEF');
$mail->isHTML(true);
$mail->Subject = 'Subject here';
$mail->Body = 'Body Goes here';
if(!$mail->send())
echo 'Mailer Error: ' . $mail->ErrorInfo;
else
echo 'Mail Sent';
Even i removed port no from the code it worked on local machine but not on server, I feel i have to make some changes on the server. i have checked server settings with phpinfo() function, The setting are almost similar like my local machine

"Almost" isn't good enough - you're missing the OpenSSL extension but you're asking PHPMailer to use encryption, which can't work without it. You just need to enable the openssl extension and it will work. There are many resources to help you do that such as this question, but you don't say what kind of server you're running so I can't be more specific.

Related

PHP - Sending mail from XAMPP using PHPMailer [duplicate]

I have been trying to send a mail using php mailer on xampp and i do get this error saying
Message could not be sent. Mailer Error: The following From address failed: xxxx2#gmail.com : Called Mail() without being connected
please, i need help on how to fix this.
Here is my code;
<?php
require( 'class.phpmailer.php' );
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "tls://smtp.gmail.com";
$mail->Port = 25;
$mail->Username = "xxxx#gmail.com";
$mail->Password = "xxxxx";
//Sending the actual email
$mail->setFrom('xxxx2#gmail.com', 'Aaron');
$mail->addAddress('xxxx2#gmail.com', 'Aaron'); // Add a recipient
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Calculation form results from ';
$mail->Body = 'testing...';
if(!$mail->send()) {
echo 'Message could not be sent. ';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
?>
Literally copied from https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
I tried with Composer and github, but couldn't get the latest version of phpmailer to work with my test php email through xampp. When I ran the program on localhost, it kept crashing out, as the email code was looking for the php mailer class.
So I went back to google, ignored composer, and downloaded a plain ordinary zip of php mailer 5.2.0, and extracted this zip directly into my 'websiteX' testing folder which is located in htdocs in xampp.
In my 'websiteX' folder I have my testmail.php file along with my phpmailer unzipped folder and it contains the class.phpmailer which actually works in my case.
I have spent a week faffing around, but now I have xampp php emails going to my test gmail account perfectly. I use chrome and notepad++ as well.
Funnily enough I had php emails with the php mail() command working too, although Gmail hard bounced 'em, which isnt great. The first thing I did last week was to get Mercury mail (included in xampp) working. I followed this link https://www.open-emr.org/wiki/index.php/Mercury_Mail_Configuration_in_Windows and managed to get xampp communicating with gmail which was great!
Good luck with your coding.

Unable to send PHPMailer through gmail account from IIS on local machine

I'm running Windows 10 Pro with IIS hosting PHP 5.6.11. In the past, an older version of PHPMail worked perfectly for sending emails via gmail in this type of windows/IIS/PHP setup. At some point in the past it quit working. So now I'm using the very latest PHPMail library as of January 6, 2018. Here is my simple example taken mostly from this gmail example.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // TLS only
$mail->SMTPSecure = "tls"; // ssl is depracated
$mail->SMTPAuth = true;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->setFrom($emailFrom, $emailFromName);
$mail->addAddress($emailTo, $emailToName);
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body");
$mail->AltBody = 'HTML messaging not supported';
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
Here is the culprit:
Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [.....\PHPMailer\src\SMTP.php line 405]
How can I solve this?
UPDATE: I found the true source of the problem and updated the error message in this post, but I don't know how to solve it.
There are many case you have to check like
open SSL in enable using you php ini
you have to check your firewall that you are successfully able to access gmail server.
etc
you can find more solution and cases here
Change below value in your code.
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 2; //Get Error Details
Hope that's work.
I have tried everything that have been written on Stackoverflow but no luck. At last I omitted the line:
$mail->isSMTP();
Of course it is not a solution but in my case I had to solve the problem and it just did it. Now I'm using php's original mail() function. By the way I tried to use Gmail and Hotmail SMTP services. I don't want anyone to spend so much time on this like me.
Everything was solved when I installed a correct certificate in IIS.

how to send mail using phpmailer on xampp

I have been trying to send a mail using php mailer on xampp and i do get this error saying
Message could not be sent. Mailer Error: The following From address failed: xxxx2#gmail.com : Called Mail() without being connected
please, i need help on how to fix this.
Here is my code;
<?php
require( 'class.phpmailer.php' );
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "tls://smtp.gmail.com";
$mail->Port = 25;
$mail->Username = "xxxx#gmail.com";
$mail->Password = "xxxxx";
//Sending the actual email
$mail->setFrom('xxxx2#gmail.com', 'Aaron');
$mail->addAddress('xxxx2#gmail.com', 'Aaron'); // Add a recipient
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Calculation form results from ';
$mail->Body = 'testing...';
if(!$mail->send()) {
echo 'Message could not be sent. ';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
?>
Literally copied from https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
I tried with Composer and github, but couldn't get the latest version of phpmailer to work with my test php email through xampp. When I ran the program on localhost, it kept crashing out, as the email code was looking for the php mailer class.
So I went back to google, ignored composer, and downloaded a plain ordinary zip of php mailer 5.2.0, and extracted this zip directly into my 'websiteX' testing folder which is located in htdocs in xampp.
In my 'websiteX' folder I have my testmail.php file along with my phpmailer unzipped folder and it contains the class.phpmailer which actually works in my case.
I have spent a week faffing around, but now I have xampp php emails going to my test gmail account perfectly. I use chrome and notepad++ as well.
Funnily enough I had php emails with the php mail() command working too, although Gmail hard bounced 'em, which isnt great. The first thing I did last week was to get Mercury mail (included in xampp) working. I followed this link https://www.open-emr.org/wiki/index.php/Mercury_Mail_Configuration_in_Windows and managed to get xampp communicating with gmail which was great!
Good luck with your coding.

sending mail using Php mailer working in local system , failing in godaddy shared server

I am trying to send an email using gmail SMTP settings.
I tried in my localhost , it worked .
I downloaded the phpMailer , in that folder I wrote a PHP file with following contents.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // 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 = 'mygmail#gmail.com'; // SMTP username
$mail->Password = 'mygmailpassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'myfromadress#gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('mytoadress.com', 'My name'); // Add a recipient
$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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
It worked in local system, But not working in the live server.
I am using Godaddy's Linux shared hosting service.
I live server its throwing the below error.
Message could not be sent.Mailer Error: SMTP connect() failed.
I cannot comment on your question because I don't have enough credentials... So I have to write an answer even though it's not technically an answer... I had similar problems a while ago. The bug was in my code. The short story is, turn on debug mode and you will have the exact reason why gmail is refusing to connect.
I'm with GoDaddy. You can't use Gmail's SMTP server. You need to use our relay server. Take a look at https://support.godaddy.com/help/article/953/what-is-the-name-of-my-hosting-accounts-relay-server for details. Feel free to follow up with me on Twitter #GoDaddyHelp if you have other questions. ^Nate

PHP Send mail error

Please help me I am New in PHP and since last 5 Hours i am try to semd mail and now really tired. Thanks.
Here is my code. I am using Gmail account.
include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$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 = "hussaintalha#gmail.com"; // GMAIL username
$mail->Password = "xxxxxxxx"; // GMAIL password
$mail->AddReplyTo("hussaintalha#gmail.com","First Last");
$mail->From = "hussaintalha#gmail.com.com";
$mail->FromName = "First Last";
$mail->Subject = "PHPMailer Test Subject via gmail";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("hussaintalha#gmail.com", "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
When I run my file I get This Error:
Warning: fopen(contents.html)
[function.fopen]: failed to open
stream: No such file or directory in
D:\xampplite\htdocs\WebEng\class.phpmailer.php
on line 1870
Warning: fsockopen()
[function.fsockopen]: unable to
connect to ssl://smtp.gmail.com:465
(Unable to find the socket transport
"ssl" - did you forget to enable it
when you configured PHP?) in
D:\xampplite\htdocs\WebEng\class.smtp.php
on line 122 Mailer Error: SMTP Error:
Could not connect to SMTP host.
First of all when you get error messages then that's great! Because in 90% of the cases you find that others have had them too and therefore you'll find plenty of information on the internet about this error message.
So step 1 when getting an error message you don't know yet is always open google and copy paste it there. But, take out any paths or other things which are uniquely connected to your system.
Then about your errors. Especially xampp light doesn't support SSL. Maybe you try an easier sendmail example first. Like a very small one and then increase it step by step.
That's what I always do, when I don't know why something doesn't work. I start with one line and see what it does, then I add another and so forth.
Let's say you start with this and see if it works:
<?php
include("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "hussaintalha#gmail.com"; // GMAIL username
$mail->Password = "xxxxxxxx"; // GMAIL password
$mail->From = "hussaintalha#gmail.com";
$mail->Subject = "PHPMailer Test Subject via gmail";
$mail->Body = "Hi, this is a test";
$mail->AddAddress("hussaintalha#gmail.com", "Hussain");
$mail->send();
?>
oh, and btw. your mail from has a .com too many!
You PHP installation (XAMPP, by the looks of it) does not support SSL. Ensure that the line
extension=php_openssl.dll
is not commented out in your php.ini, restart Apache, and if that still doesn't work try overwriting (or copying) ssleay32.dll and libeay32.dll from your PHP directory into Apache's binary (.exe) directory then restart Apache.

Categories