0

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;
}
?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Geoff_S
  • 4,917
  • 7
  • 43
  • 133

1 Answers1

1

Maybe this answer will help: phpmailer error "Could not instantiate mail function" As you mention Powershell, I would suspect the OS (Windows) is the issue.

Onyx
  • 876
  • 1
  • 10
  • 18
  • Thank you, I tried it on our prod server and it worked flawlessly. I used the google SMTP settings to test locally. Much appreciated! – Geoff_S Oct 10 '17 at 13:10