I'm trying to create a contact form. And I searched all over the internet how to send email, and they always say that it is better to use PHPMailer than mail() function.
The contact form consists of: Name, Email, Comments, and a Send Button.
I just followed this tutorial: https://alexwebdevelop.com/phpmailer-tutorial/ but it's not working as I always got the error called: 'Could not instantiate mail function.' when I already installed the Composer.
Proof that I've already installed the composer: Composer installed with autoload.php
Here's my code inside the php tags:
use PHPMailer\PHPMailer\PHPMailer;
require 'C:\xampp\composer\vendor\autoload.php';
if(isset($_POST['send'])) {
$em = $_POST['email'];
$nm = $_POST['name'];
$msg = $_POST['comments'];
$mail = new PHPMailer();
$mail->setFrom($em, $nm);
$mail->addAddress('[email protected]', 'Admin');
$mail->Subject = 'Concern';
$mail->isHTML(TRUE);
$mail->Body = '$em';
if(!$mail->send()) {
echo $mail->ErrorInfo;
}
}
Thank you for answering this question! It'll be a big help!
UPDATE:
Content/File of the composer.json:
{
"require": {
"phpmailer/phpmailer": "^6.0"
}
}