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
Related
I have a local Apache2 server running on Debian/Bullseye. I've been pulling my hair out trying to get PHPMailer to do anything. There seem to be 2 different methods for installing PHPMailer - 1 is to use composer, which is the first one I tried. It creates a vendor folder in the site's root, which includes an autoload.php file, among other things. That file contains:
<?php
// autoload.php #generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitd359baac21f520c04e608f4eed750560::getLoader();
Which doesn't look like it's complete (no closing tag). Anyway, I can't get the "test.php" samples to work.
The other method is to download the .zip file from the gethub site and extract it into the site's root. This, after renaming, gives me a PHPMailer folder. Using the "mailer.php" samples doesn't do anything either.
In both cases I've modified the smtp information to use the domain's actual account information (sending e-mail, login password, smtp server name, host's smtp security and port settings) but I'm not even getting it rejecting the mail. Nothing is happening. I'm left with a blank web page.
I do have php running, as a previous php script I'd used still works (from my test site - the live site now insists on smtp and won't let me install PEAR modules).
Here's the mailer.php script I'm working with - with some details hidden:
<?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\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
Try
{
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'mail.<domain>.ca'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'mail#<domain>.ca'; //SMTP username
$mail->Password = '<secret>'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('mail#<domain>.ca', ‘from me’);
$mail->addAddress('gary#<domain>.ca', ‘to me’); //Add a recipient
// $mail->addAddress('Recipient#emailaddress.com'); //Name is optional
// $mail->addReplyTo('yourname#domain.com', ‘Your Name’);
// $mail->addCC('cc#example.com');
// $mail->addBCC('bcc#example.com');
//Attachments Optional
// $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 = 'Here is the subject';
$mail->Body = 'This is the HTML message body in bold!';
$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}";
}
?>
The TLS line are from the hosting company so I assume they are correct.
I've commented out options that I don't need for testing but it still doesn't work. Can anyone figure out what I'm doing wrong?
Thanks.
OK, got it. The host company provided the test code and their sample used smtp.domain.com. In actuality, their smtp server is mail, not smtp. I guess that when faced with a non-existent server, the code hangs...
I have trouble sending emails from my iPage webserver.
Firstly I watched a tutorial on how to use PHPMailer and the guy used gmail smpt server. That method worked flawlessly on localhost, but it doesn't work on the webserver and I cant find a solution for this anywhere. Seems like the authentication didn't work because I've got an email from google security saying someone was trying to log in to my gmail (it was 100% ipage), even accepting the new login doesn't work
If there is a possibility I'd like to send mail from my custom domain email rather than form 3rd party gmail.
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
require 'phpmailer/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = "587";
$mail->Username = ".....#gmail.com";
$mail->Password = ".....";
$mail->Subject = ".....";
$mail->setFrom('.....#gmail.com');
$mail->isHTML(true);
$mail->Body = ".....";
$mail->addAddress('.....#....');
if ($mail->send()) echo "OK";
else echo "BAD";
$mail->smtpClose();
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);
I have written some code to send email. Now i have multiple scripts that uses PHPMailer to send emails. So what i did was i wrote all my SMTP settings in a file after including PHPMailerAutoLoad.php but it still is throwing an error 'Class PHPMailer not found.'
Following is the code snippet of mailsetting.ph which has settings regarding my SMTP Server.
<?php
include("/../PHPMailer/PHPMailerAutoload.php");
$mail= new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->Port =465;
$mail->SMTPSecure = 'ssl';
$mail->From='info#vishalkhare.com';
$mail->FromName='Vishal Khare';
$mail->addReplyTo('info#vishalkhare.com', 'Information');
?>
It says 'Fatal error: Class 'PHPMailer' not found in mailsetting.php on line 3' which clearly means that include statement is executing properly. But Still Class PHPMailer is not included.
I also tried including the class.phpmailer.php file
<?php
include("../class.phpmailer.php");
include("../PHPMailer/PHPMailerAutoload.php");
?>
It is still not working. Please help me out and let me know what to do to include PHPMailer class in the file?
P.S. - It is working on a XAMPP Server but not working as i move the code to a webserver. A godaddy Web server precisely
Problem is not in loading PHPMailAutoLad. Unfortunately Godaddy doesn't support emails of gmail,yahoo,aol,live,hotmail,etc., IF you are using linux cPanel hosting panel then make these changes in your php files
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->ssl = false;
$mail->authentication = false;
I am implementing mail functionality by using PHP mailer.
The code is not working on online but its working on local machine. On local machine code sends the mail successfully but on online website it is showing following error:
SMTP -> ERROR: Failed to connect to server: ()
SMTP Error: Could not connect to SMTP host.
Code is:
<?php
include "classes/class.phpmailer.php"; // include the class name
$mail1 = new PHPMailer(); // create a new object
$mail1->IsSMTP(); // enable SMTP
$mail1->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail1->SMTPAuth = true; // authentication enabled
$mail1->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail1->Host = "smtp.gmail.com";
$mail1->Port = 465; // or 587
$mail1->IsHTML(true);
$mail1->Username = "yourmail#gmail.com";
$mail1->Password="password";
$mail1->SetFrom("yourmail#gmail.com");
$mail1->Subject = "Working";
$mail1->Body ="Hi, you got email";
$mail1->AddAddress("yourmail2#gmail.com");
$mail1->Send();
?>
First you have to edit the "php.ini" To find this file display the phpinfo by using following code from the WAMP server. Create one php file and add this content.
<?php
echo phpinfo();
?>
There search for "Loaded Configuration File" That will be the path to your php.ini.
In this file remove the ;(semi colon) given to extension=php_openssl.dll.
After downloading PHPMailer package
Extract Copy the full folder into your project folder.
Use the doc folder for help. In test folder there is one file called testemail.php.
Change the parameter as your need. (Example given below).
Then in the browser type 127.0.0.1/PHPMailer/test/testemail.php.
Then it will show successful message if email sent, else it will give error message.
Example:
//add these codes if not written
$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;
//You have to change these parameters to your requirements.
$mail->Username = “abc#gmail.com”; // GMAIL username
$mail->Password = “abcdefgh”; // GMAIL password
//..code ... There are many other functions to attach file etc.. For that refer doc file.
$mail->AddAddress(“destination#gmail.com”,”Nick name”);