使用PhpMailer发送附件,路径由用户选择
我正在尝试使用PHPMailer发送一些电子邮件,我想在其中附加一个pdf文件。必须将此文件的名称从用户中选择到html中的select标记中。尤其是接收输入的代码使用PhpMailer发送附件,路径由用户选择,php,email,pdf,phpmailer,fpdf,Php,Email,Pdf,Phpmailer,Fpdf,我正在尝试使用PHPMailer发送一些电子邮件,我想在其中附加一个pdf文件。必须将此文件的名称从用户中选择到html中的select标记中。尤其是接收输入的代码 <select name="Attachment"> <?php $files=scandir("/pathtotherightfolder/"); for($i=0;$i<count($files
<select name="Attachment">
<?php
$files=scandir("/pathtotherightfolder/");
for($i=0;$i<count($files);$i++)
{
if(substr($files[$i],-3,3)=="pdf")
echo "<option value='".$files[$i]."'>".$files[$i]."</option>";
}
?>
<option value="Nessuno">Nessuno</option>
</select>
还加
chunk_split(base64_encode(file_get_contents($url)));
第二:
第三:
在第一种和第三种情况下,我收到了附件,但内容已损坏,在第二种情况下,我收到了没有附件的邮件。
是否有人已经尝试过做类似的事情?有什么建议吗?看起来您的代码基于一个过时的示例,因此请确保您使用的是最新版本。你说它不起作用,但不说明如何起作用。第二种方法是最简单的,并且提供了许多示例,它们可以毫无问题地完成相同的操作—请发布您收到的原始消息源。不要自己尝试对附件进行编码,你只会弄坏东西-PHPMailer会为你做所有这些。@Synchro:我已经演示了如何:“在第一种和第三种情况下,我收到附件,但内容已损坏,在第二种情况下,我收到没有附件的邮件。”我尝试了第二种方法的许多变体(这实际上是记录最多的)但有些示例甚至不发送电子邮件,而有些示例发送电子邮件时不附带附件否,您显示了代码,但没有显示错误消息,也没有检查返回值。@Synchro:对不起,先生,我添加了返回值和错误,如信号先生所示(作为代码中的注释)“这一个返回bool(false)”-请应用一点含义-一个false结果意味着它失败。您的路径不正确或权限错误。请检查所有参数值。一次解决一个问题。
chunk_split(base64_encode(file_get_contents($url)));
$url="Samepathofthehtml".$_POST['Attachment'];//this path is correct
$messaggio->AddAttachment(realpath($url), $_POST['Attachment'], $encoding='base64' , $type='application/pdf');//this one returns bool(false) and sends the email with no attachments
require("fpdf.php");
require("fpdi.php");
$pdf = new FPDI();
$pageCount = $pdf->setSourceFile("Samepathasbefore".$_POST['Attachment']);
$tplIdx = $pdf->importPage(1);//just a try with one page
$pdf->AddPage();
$pdf->useTemplate($tplIdx, 10, 10, 90);
$doc = $pdf->Output('', 'S');//if I try $pdf->Output(); i see the pdf correctly on my browser (so i deduce all the previous instructions are correct)
//And in the sending code
$messaggio->AddStringAttachment($doc, $_POST['Attachment'], $encoding='base64' , $type='application/pdf');//I obtain the same return value of the 2nd