PHPMailer autoload.php not able to open - php

I am currently hosting a website on GoDaddy and recently I added a contact form that will send me emails when people fill it out. It works perfectly when I use XAMPP, but once I uploaded the same code onto the GoDaddy servers, it gives me a HTTP ERROR 500.
I am using PHPMailer and Gmail's SMTP service. This is the current code that works with XAMPP:
<?php
require_once "vendor/autoload.php";
$name = $_POST["name"];
$email_from = $_POST["email"];
$telephone = $_POST["telephone"];
$message = "Name: ".$name."\r\n".
"Email: ".$email_from."\r\n".
"Telephone: ".$telephone."\r\n";
$email_to = "myemail#gmail.com";
if(isset($_POST['submit'])){
$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "myemail#gmail.com";
$mail->Password = "password";
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->From = $email_from;
$mail->FromName = $name;
$mail->addAddress($email_to);
$mail->addReplyTo($email_from);
$mail->Subject = "Info";
$mail->Body = $message;
if ($_POST["submit"]){
if(!$mail->send()){
echo "Mailer error: " . $mail->ErrorInfo;
}
else{
echo "Message sent successfully";
}
}
}
Since it was giving me HTTP ERROR 500, I decided to look into the error logs given by GoDaddy. This is the error:
[13-Dec-2018 19:33:13 UTC] PHP Fatal error: require_once(): Failed opening required '/home/namesearch/public_html/vendor/composer/autoload_real.php' (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/namesearch/public_html/vendor/autoload.php on line 5
Please help!!! I have looked up countless solutions and I just don't know how to fix it. I even tried putting my path as: /home/namesearch/public_html/vendor/composer/autoload_real.php and /home/namesearch/public_html/vendor/composer/autoload.php but nothing works.

I'm adding on the comment from #h2oooooo here. This is something that drove me insane when I first started learning composer. As he said above, make sure you've uploaded all of your dependencies, and then updates your autoload files. But, here's exactly how to do that:
1) Go to the root of your project in your local environment.
2) Then run composer update
3) I recommend just uploading the entire project again, unless you use filezilla folder compare to show which files are different, it'll be hard to know for sure.
If you're uploading your project from a git repo, then double check that your .gitignore file isn't ignoring your /vendor folder, as it often does by default.

I had a similar problem with configuring mustache so I hope this helps. My problem was with this line:
require_once "vendor/autoload.php";
It wasn't picking up the correct PHP include path.
Add the absolute path of the folder one level before vendor to your PHP include path.
Place this code right before the require.
$includePath = get_include_path() . ";ABSOLUTE PATH OF FOLDER ONE LEVEL BELOW VENDOR";
set_include_path($includePath);

Related

.htaccess file doesn't exist

I am beginner in web development. I launched website from hostgator. in my index.php I used phpmailer but when I click send button "HTTP ERROR 500" appears. I think it happens because I don't have .htaccess file. I am searching now but can't find .htaccess example to add to my project. can somebody show me an example of .htaccess? and also tell me where to add it - homepage or my website project directory where index.php exists?
in my index.php file I started from bootstrap template and modified by myself. purpose of .htaccess file is to send emails with phpmailer. here is my index.php document:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exceptions;
require 'phpmailer/src/Exceptions.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
if(isset($_POST["send"])){
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'info#mil-data.com';
$mail->Password = 'dgqncmczasdygmwjwbr';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setForm('info#mil-data.com')
$mail->addAddress($_POST["email"]);
$mail->isHTML(true);
$mail->Subject = $_POST["subject"];
$mail->Body = $_POST["message"];
$mail->send();
echo
"
<script>
alert('Sent Successfully');
document.location.href = 'index.php'
</script>
";
}
You can read this article, there it shows an htaccess and also explains a bit of its operation, and you can also check this htaccess generator: https://julianpoemp.github.io/ngx-htaccess-generator/#/generator

problem sending mail with PHPMailer on AWS AMI instance

I'm fairly new to UNIX, coming from a Windows background.
I've created an instance on Amazon EC2 and installed apache, PHP and MySQl.
i've successfully uploaded the files for a PHP website.
Everything works well, except i have a problem sending mails from a contact form.
i went through the AWS tutorial here: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-php.html
i successfully installed composer and ran it in Putty and i see the vendor directory is created and the phpmailer files are downloaded.
site structure looks like this:
html
test_mail.php
--vendor
----bin
----composer
----phpmailer
----autoload.php
I've tried using the sample email script included in the tutorial which looks something like this :
// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
// Instantiate a new PHPMailer
$mail = new PHPMailer;
// Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 2;
// Replace sender#example.com with your "From" address.
// This address must be verified with Amazon SES.
$mail->setFrom('sender#example.com', 'Sender Name');
but i get the following error:
Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in /var/www/testSite/html/test_mail.php:10 Stack trace: #0 {main} thrown in /var/www/testSite/html/test_mail.php on line 10
line 10 is
$mail = new PHPMailer;
so i'm stumped as to what the problem is.
The required PHPMailer files seem to have been created correctly by composer, and the path to 'vendor\autoload.php' should be correct.
is it possible there's something in the server setup I've missed?
any suggestions gratefully received.
David
AWS Does not have autoload anymore, and PHPMailer should be initialized as follows:
<?php
require("/home/site/libs/PHPMailer-master/src/PHPMailer.php"); require("/home/site/libs/PHPMailer-master/src/SMTP.php");
$mail = new PHPMailer\PHPMailer\PHPMailer();
$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 = "xxxxxx";
$mail->Password = "xxxx";
$mail->SetFrom("xxxxxx#xxxxx.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("xxxxxx#xxxxx.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
} ?>
Thank you Lawrence for pointing me in the right direction...
The problem was, as you pointed out, with the version of phpmailer being used.
when i changed the composer.json for this project to
{
"require": {
"phpmailer/phpmailer":"~6.0"
}
}
and ran the composer update my scripts now run (mostly) successfully.
It looks like the example given in the AWS docs is incorrect as it says to use phpmailer 5.2, but the script it gives only works in version 6 onwards.
thank you!
David

Send email using Gmail SMTP CodeIgniter [duplicate]

I'm googling for how to this error a lot of hours. I've tried all solutions from this topic without luck. <? phpinfo(); ?> (the only difference I'm using Appserver instead of IIS) it doesn't show anything realated to SSL. What else should I try?
The full error message:
<b>Warning</b>: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: 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 <b>C:\AppServ\www\webgitz\test\class.smtp.php</b> on line <b>122</b><br />
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (27010016)
and code:
<?php
require_once "validation.php";
require_once "PHPMailer.php";
require_once "class.smtp.php";
$email= "foo#gmamcil.com";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port =465; // set the SMTP server port
$mail->Host = "smtp.gmail.com"; // GMAIL's SMTP server
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->Username = "xxxxxx#gmail.com"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->AddReplyTo("XXXXX#gmail.com","AAAA"); // Reply email address
$mail->From = "XXXX#gmail.com";
$mail->FromName = "...."; // Name to appear once the email is sent
$mail->Subject = "...."; // Email's subject
$mail->Body = "Hello World,<br />This is the HTML BODY<br />"; //HTML Body
$mail->AltBody = "..."; // optional, commentA out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($msg); // [optional] Send body email as HTML
$mail->AddAddress("$email", "fooo"); // email address of recipient
$mail->IsHTML(true); // [optional] send as HTML
if(!$mail->Send()) echo 'ok'; else echo 'error';
?>
Check your php.ini file, on it, if you have this:
;extension=php_openssl.dll
change it to
extension=php_openssl.dll
After that, remember to restart Apache, either using any control panel that Appserver offers, or using the services windows on the control panel of the system.
Also be sure that php_openssl.dll is on a folder that the system can reach, many people use to solve the problem of dll location problems by copying them to C:\windows or C:\windows\system32. Although that shouldn't be necessary.
After that, execute a file with phpinfo and check that it's enabled.
I have read somewhere, can't pinpoint it, that some installation of that kind of wamps have more that one php.ini, but only one is really active, could it be that you have edited the wrong one?
The proper answer is to replace the line
;extension=php_openssl.dll
in the php.ini file with
extension=php_openssl.dll
If you cant find extension=php_openssl.dll in the php.ini file, then just simply append the following line to the file:
extension=php_openssl.dll
This should work!
I had a similar error with ssl for hours.
What worked for me was copying php\libeay32.dll, php\ssleay32.dll and php\ext\php_openssl.dll from the php directory to the Apache2.2\bin directory. Then restart apache.
For some people, those solutions don't work.
For me the solution was this: copy dll libeay32.dll and ssleay32.dll to the bin directory of the server - apache.
The solution suggest in a comment in:
http://php.net/manual/fa/openssl.installation.php
When I look in the error log, I understood that the problem was in loading the dll's and putting them to the server directory was the only way.

PHPMailer with PHP 5.3.27

I am stuck with this issue. I tried to search it, but no help. I have a very small application running on my local WAMP. I have tested my application on a WAMP server,
and mailing service works perfectly. My WAMP has PHP 5.4, but when I deployed the same code on a hosting server(Network Solutions with PHP 5.3.27) it is not working. Below is
my code:
<?php
require 'PHPMailerAutoload.php';
/*
other code;
*/
//Mailing settings
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.server_name.net';
$mail->SMTPAuth = true;
$mail->Username = ' admin_user_name#server_name.net';
$mail->Password = 'password';
$mail->SMTPDebug = 1;
$mail->From = 'from_address#server_name.net';
$mail->FromName = 'from_name';
$mail->addAddress('receiver_add#abc.com', 'Receiver');
$mail->addCC('cc_address#abc.com','XYZ');
$mail->WordWrap = 50;
$mail->Subject = 'Subject_Was_Not_Long';
$body=" ABCD BODY.\n";
$mail->Body = $body;
if(!$mail->send()) {
header('Location: Same_File.php?registered=false');
} else {
header('Location: Same_File.php?registered=true');
}
?>
I am not sure what I have to do, because I am not able to access the PHP config as well. Please help!
Extra bit of info:
Configuration Hosting Server My PC
System Linux Windows
Server API CGI/Fast CGI Apache Handler 2.0
Virtual Directory Support Disabled Enabled
Thread Saftey Disabled Enabled
Thank You...
Had the same problem just now. The problem is fixed in the current GitHub version of PHPMailer. PHPMailer initially checks for version '5.0.0', but it contains the array syntax [] which is only active in version 5.4. If you replace all the [] in the PHPMailer classes with array(), it works.

PHP : send mail in localhost

I would like to send email through php code hosted locally.
<?php
$email = "myemail#local.com";
$titre = "My subject";
$message = "Text message !";
mail($email, $titre, $message);
?>
When I run this code, I get the following error :
Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\...
I went into the php.ini file and it seems to be already well configured.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
How can I fix this ?
Thank you
It is configured to use localhost:25 for the mail server.
The error message says that it can't connect to localhost:25.
Therefore you have two options:
Install / Properly configure an SMTP server on localhost port 25
Change the configuration to point to some other SMTP server that you can connect to
I spent hours on this. I used to not get errors but mails were never sent. Finally I found a solution and I would like to share it.
<?php
include 'nav.php';
/*
Download PhpMailer from the following link:
https://github.com/Synchro/PHPMailer (CLick on Download zip on the right side)
Extract the PHPMailer-master folder into your xampp->htdocs folder
Make changes in the following code and its done :-)
You will receive the mail with the name Root User.
To change the name, go to class.phpmailer.php file in your PHPMailer-master folder,
And change the name here:
public $FromName = 'Root User';
*/
require("PHPMailer-master/PHPMailerAutoload.php"); //or select the proper destination for this file if your page is in some //other folder
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465"); //No further need to edit your configuration files.
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPSecure = "ssl";
$mail->Username = "trials.php#gmail.com"; //account with which you want to send mail. Or use this account. i dont care :-P
$mail->Password = "trials.php.php"; //this account's password.
$mail->Port = "465";
$mail->isSMTP(); // telling the class to use SMTP
$rec1="trials.php#gmail.com"; //receiver. email addresses to which u want to send the mail.
$mail->AddAddress($rec1);
$mail->Subject = "Eventbook";
$mail->Body = "Hello hi, testing";
$mail->WordWrap = 200;
if(!$mail->Send()) {
echo 'Message was not sent!.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo //Fill in the document.location thing
'<script type="text/javascript">
if(confirm("Your mail has been sent"))
document.location = "/";
</script>';
}
?>
You will need to install a local mailserver in order to do this.
If you want to send it to external e-mail addresses, it might end up in unwanted e-mails or it may not arrive at all.
A good mailserver which I use (I use it on Linux, but it's also available for Windows) is Axigen:
http://www.axigen.com/mail-server/download/
You might need some experience with mailservers to install it, but once it works, you can do anything you want with it.
try this
ini_set("SMTP","aspmx.l.google.com");
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: test#gmail.com" . "\r\n";
mail("email#domain.com","test subject","test body",$headers);
It is possible to send Emails without using any heavy libraries I have included my example here.
lightweight SMTP Email sender for PHP
https://github.com/Nerdtrix/EZMAIL
Tested in both environments production and development.
and most importantly emails will not go to spam unless your IP is blacklisted by the server.
cheers.

Categories