homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

attaching a file with the confirmation email
email php attachment form

 7:19 am on Aug 9, 2013 (gmt 0)

Can anyone give me some tips on how to attach a file to the confirmation file of a web form.

I found how to upload files by the user and send them off but what i want achieve is:
Users fills in the form, the receive an html email with all the data they provided. I would like to attach a pdf file with terms & conditions and a doc or pdf file with additional information about the course.
All the files are on my server.

[ehbo.themafeestenontvangen.nl...] if you would like to see what I mean.



 1:47 pm on Aug 9, 2013 (gmt 0)

why don't you use a ready mail library? it will assist you in things like that.
i personally use the swiftmailer when i want to send emails with attachemtns


 1:56 pm on Aug 9, 2013 (gmt 0)

I have red about that but I have set everything up and running with the mail();
I am not familiar with the phpmailer or swiftmailer library.
Omoutop Do you have an example or a short explination on how it works?


 2:11 pm on Aug 9, 2013 (gmt 0)

sure - here is a small demo for the swiftmailer

// include the lilbrary
require_once $_SERVER['DOCUMENT_ROOT'].'/mailer/swift/lib/swift_required.php';
// set transport method - this is for mail().. in manual options for smpt
$transport = Swift_MailTransport::newInstance();
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// $messageTEXT is your non-html message
// $messageHTML is yout html message
// $attachFile path to your local file

// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('subject here')
// Set the From address with an associative array
->setFrom(array('example@test.com' => Website Autoreport')
// Set Return Address
// Set the To addresses with an associative array
->setTo(array('user@test.com'=>'Customer name'))
// Set the Bcc addresses with an associative array
->setBcc(array('test@test.com'=>'Test1', 'test2@greeka.com'))
// Set character set
// Set Priority to Normal (1:Highest -> 5:very low)
// Give it a body
// And optionally an alternative body
->addPart($messageHTML, 'text/html')
// attache file

// Send the message
$result = $mailer->send($message);

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved