使用PHPMailer发送电子邮件并创建PDF

时间:2018-02-22 02:04:47

标签: php phpmailer

我有一个运行FPDF的脚本,可以在文件夹中创建和存储PDF文件。

工作正常。

我的问题是,我能在同一个脚本中发送电子邮件吗?

我尝试了但是我总是得到" Page无法显示"

编辑我不希望文件附加到电子邮件中。我只想发送一封包含所有措辞的电子邮件。

不要将我的整个代码粘贴到有问题的结尾:

//display pdf

mkdir("FileBrowser/files/$name", 0777);

$total = count($_FILES['files']['name']);

// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
 $tmpFilePath = $_FILES['files']['tmp_name'][$i];

//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "FileBrowser/files/$name/" . $_FILES['files']['name'][$i];

//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {

  //Handle other code here

}
}
}


$filename = "FileBrowser/files/$name/$name.pdf";
$pdf->Output($filename, 'F');

require ('PHPMailer/class.phpmailer.php');

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = '****';                 // Specify main and backup server
$mail->Port = 587;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               

$mail->Username = '****';                // SMTP username
$mail->Password = '****';                  // SMTP password

$mail->From = 'Testing@test.co.za';
$mail->FromName = 'Testing';
$mail->AddAddress('****', 'John Smith');  // Add a recipient

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

?>

0 个答案:

没有答案