输出'',S;用Mpdf和PHPmailer破坏代码

问题描述

我正在尝试使用mPDF和PHPMailer设置发送pdf附件。 将输出下载到浏览器时,mPDF正常运行,当我将其更改为Output('',S)时,代码停止处理Error 500,并且我尝试了不同版本的邮件程序代码,但都没有碰到运气。我找不到语法上的任何错误,所有在线教程似乎都同意该代码。我很沮丧

我的代码

<?PHP

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require_once __DIR__ . '/vendor/autoload.PHP';


// Grab variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];

$mpdf = new \Mpdf\Mpdf();

$data = "";
$data .= "<h1>Testing this</h1>";

//Add Data
$data .='<strong>First Name</strong> '. $fname.'<br>';
$data .='<strong>Last Name</strong> '. $lname.'<br>';
$data .='<strong>Email</strong> '. $email .'<br>';

if($message)
{
    $data .='<br/><strong>Message</strong><br/> '. $message.'<br>';
}

//WritePdf
$mpdf->WriteHtml($data);

//output to bowser
$pdf = $mpdf->output('',S);

$enquirydata = [
'First Name' => $fname,'Last Name' => $lname,'Email' => $email,'Message' => $message
];

sendEmail($pdf,$enquirydata);

function sendEmail($pdf,$enquirydata)
{

$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'in-v3.mailjet.com';                    // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'username';                     // SMTP username
    $mail->Password   = 'password';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
    $mail->Port       = 587;                                    // TCP port to connect to,use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->setFrom('myemails@gmail.com','Test Form');
    $mail->addAddress('joe@example.net','Joe User');     // Add a recipient
    $mail->addReplyTo('info@example.com','information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    // Attachments
 
    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message Could not be sent. Mailer Error: {$mail->ErrorInfo}";

}
}

?>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)