swiftmailer and email form with attachment - beginner

末鹿安然 提交于 2019-11-30 08:43:02
André Catita

There's a simple way to do this, here you go:

$message->attach(
Swift_Attachment::fromPath('/path/to/image.jpg')->setFilename('myfilename.jpg')
);

That's one way SwiftMail can do this, now just the /tmp file, and turn the above into the following:

Assuming: fileatt is the variable for the $_FILE, ['tmp_name'] actually is the tmp file that PHP creates from the form upload.

$message->attach(
Swift_Attachment::fromPath($_FILES['fileatt']['tmp_name'])->setFilename($_FILES['fileatt']['name'])
);

More information on SwiftMail Attachments can be found on this docs page

More information on $_FILES can be found here on w3schools, despite I don't like w3schools, this page is solid.

Another way to do this, using only a single variable for path and filename is:

$message->attach(Swift_Attachment::fromPath('full-path-with-attachment-name'));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!