I don’t use composer.
I have a simple contact form that I want to send the text through
my site’s email account to gmail.
http://elcomass.com/elcomass-contact.php
I’ve copied codes from multiple sites and tried atleast five
but none worked. Current code is the latest I tried
I tried or viewed these links, didn’t help me.
This is my last resort, because I’ve also tried tutorials on sites.
https://github.com/PHPMailer/PHPMailer#a-simple-example
Sending mail with PHPMailer (SMTP)
https://codeforgeek.com/phpmailer-ultimate-tutorial/
https://www.cloudways.com/blog/send-emails-in-php-using-phpmailer/
https://alexwebdevelop.com/phpmailer-tutorial/
Currently researching:
https://www.google.com/search?client=firefox-b-d&q=PHP+Fatal+error%3A++require%28%29%3A+Failed+opening+required+%27class.PHPMailer.php%27
When you submit the form, all you get is a blank page.
In the error log this is the most common problem:
PHP Fatal error: Class ‘PHPMailer’ not found in /home/elcomass/public_html/elcomass-sendmail.php on line 6
PHP Warning: require(class.PHPMailer.php): failed to open stream: No such file or directory in /home/elcomass/public_html/elcomass-sendmail.php on line 2
[13-Jul-2019 12:27:14 UTC] PHP Fatal error: require(): Failed opening required ‘class.PHPMailer.php’ (include_path=’.:/opt/cpanel/ea-php56/root/usr/share/pear’) in /home/elcomass/public_html/elcomass-sendmail.php on line 2I’ve tried making folders, manually placing phpmailer items there.
As it is now, its directly placed in my public_html without a folder
and it still doesn’t work. Same for Exception.php, STMP.php
<?php
// This is one way I tried
use PHPMailer;
require 'PHPMailer.php';
// #2
require 'class.PHPMailer.php';
// #3
require 'PHPMailer.php';
// #4
require 'test/class.PHPMailer.php';
// #5
require 'testclass.PHPMailer.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$subject = $_POST['subject'];
$message = $_POST['message'];
$email = $_POST['email'];
$name = $_POST['name'];
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'xxxx'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'xxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = xxx; // TCP port to connect to
//Recipients
$mail->setFrom($email, $name);
$mail->addAddress('[email protected]', 'elcomass'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
i want the contact form to send email to a gmail address.
I have the email address specifications for the site through cPanel.
2
Answers
After much work with phpmailer, I managed to solve my issues. I was doing couple of things wrong, as errors showed, but for anyone interested be careful copying details about your domain e-mail and don't call SESSION in the same page where phpmailer code is.
Use this code. its work for me.