我在发送电子邮件时遇到问题,我的身体是空的,但是在此邮件中有附件。 w
我应该怎么做才能将电子邮件发送给任何用户,而无需在body
部分中输入任何消息或文本?
<?php
include('db.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";
$id = $_GET['id'];
$query = "select * from access where uid='$id'";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_assoc($result);
$mail = new PHPMailer(true);
try {
$mail->setFrom('sender@gmail.com');
$mail->addAddress('receiver@gmail.com');
if($row['attachments']!=null)
{
$array = explode(",",$row['attachments']);
$count = count($array);
if($count > 0 && $row['attachments'] != 'null'){
for ($i=0; $i < $count ; $i++) {
$file_to_attach = './attachment/' . $array[$i];
$mail->addAttachment($file_to_attach, $array[$i]);
}
}
}
$mail->isHTML(true);
$mail->Subject = $row['subject'];
$mail->Body = $row['body'];
$mail->send();
echo 'Message has been sent';
}
catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}