I'm having issues using PHPMailer. My script is below, and I've omitted my sql queries as they are working, the only issue is the mail portion. The main idea is that the queries will run and then I have a block below that creates a CSV from that data. I want to send the csv as an attachment anytime the script runs.
When I run the script below in PowerShell, I get an error
mail error: Could not instantiate mail function
I've included everything and it found the class fine, but for some reason I keep getting this. I'm new to PHPMailer, so I'm hoping there's an obvious piece I'm missing. I'm running this locally.
Here's the script:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '/common/site_globals.php';
require 'phpmailer/vendor/autoload.php';
print_r(get_included_files());
if (!$result) die('Couldn\'t fetch records');
$num_fields = mysqli_num_fields($result);
$headers = array();
while ($fieldinfo = mysqli_fetch_field($result)) {
$headers[] = $fieldinfo->name;
}
$fp = fopen('dailyReportTestPHP.csv', 'w');
if ($fp && $result) {
fputcsv($fp, $headers);
while ($row = $result->fetch_array(MYSQLI_NUM)) {
fputcsv($fp, array_values($row));
}
fclose($fp);
}
$mail = new PHPMailer(true);
try{
$mail->setFrom("hnorman@jacksonfurnind.com");
$mail->addAddress("thenorman138@gmail.com");
//$mail->addAttachment($fp);
$mail->isHTML(true);
$mail->Subject = "Test";
$mail->Body = "Test";
$mail->Send();
echo 'message sent';
} catch (Exception $e){
echo 'message failed';
echo 'mail error:' . $mail->ErrorInfo;
}
?>