Email 使用php mailer发送带有附件的电子邮件
有人能告诉我用phpMailer发送带有附件的电子邮件的步骤吗。 我已经准备好所有的代码发送电子邮件本身,它的工作很好,但我不知道如何发送附件。我有表单,若我从POST上输入的文件中得到值,它只会给我文件名,而不是完整路径。我想为了添加附件,我需要获得文件的完整路径,对吗? 我不需要在服务器上存储文件,只需要通过电子邮件发送即可 我找到了解决方案: 首先,在我的表单中,我必须包含enctype=“multipart/form data”以发送文件,因此必须如下所示:Email 使用php mailer发送带有附件的电子邮件,email,attachment,phpmailer,Email,Attachment,Phpmailer,有人能告诉我用phpMailer发送带有附件的电子邮件的步骤吗。 我已经准备好所有的代码发送电子邮件本身,它的工作很好,但我不知道如何发送附件。我有表单,若我从POST上输入的文件中得到值,它只会给我文件名,而不是完整路径。我想为了添加附件,我需要获得文件的完整路径,对吗? 我不需要在服务器上存储文件,只需要通过电子邮件发送即可 我找到了解决方案: 首先,在我的表单中,我必须包含enctype=“multipart/form data”以发送文件,因此必须如下所示: <form metho
<form method="POST" action="send.php" enctype="multipart/form-data">
inputs...
</form>
然后,我准备该文件的路径,该文件现在位于临时目录中,并标识新文件名:
$attachment_path = $this->file['tmp_name'];
//If need to give new name for the file:
//$newfilename = pathinfo(basename($this->file['name']));
//$attachment_name = "attachment_new_name.".$newfilename['extension'];
$attachment_name = basename($this->file['name']);
$mail->AddAttachment($attachment_path, $attachment_name);
完成了!文件现在已附加。我只更改了$mail->AddAttachment($\u FILES['file']['tmp\u name'],$\u FILES['file']['name']);但是它成功了,谢谢
$attachment_path = $this->file['tmp_name'];
//If need to give new name for the file:
//$newfilename = pathinfo(basename($this->file['name']));
//$attachment_name = "attachment_new_name.".$newfilename['extension'];
$attachment_name = basename($this->file['name']);
$mail->AddAttachment($attachment_path, $attachment_name);