我的函数的第一部分使用PHP的fputcsv生成一个CSV文件,然后用我已经安装的PHPMailer给该CSV发电子邮件。
从数组.生成CSV文件。
$output = fopen("php://output",'w') or die("Can't open php://output");
// Add column headings.
fputcsv($output, array('SKU', 'ASIN', 'Current Rating', 'Previous Week', 'Difference', 'Category', 'Total Ratings'));
foreach( $ratings as $rating ) {
fputcsv( $output, $rating );
}
fclose($output) or die("Can't close php://output");通过PHPMailer发送电子邮件
// Create a new PHPMailer instance
$mail = new \PHPMailer\PHPMailer\PHPMailer();
// Tell PHPMailer to use SMTP
$mail->isSMTP();
// Set the hostname of the mail server
$mail->Host = 'smtp.eu.mailgun.org';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
// Set who the message is to be sent from
$mail->setFrom('', '');
$mail->Subject = 'Weekly ASIN Ratings Report';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
// Attach an image file
$mail->addAttachment('');
// Send the message, send errors to Sentry.
if (!$mail->send()) {
\Sentry\captureMessage( $mail->ErrorInfo );
} else {
echo 'Message sent!';
}我试过什么
$mail->addAttachment($output);我收到了电子邮件,但根本没有附件。
发布于 2021-03-18 17:42:31
你可以用它就像-
$mail->AddAttachment( $filePath , 'filename.csv' );https://stackoverflow.com/questions/66695871
复制相似问题