PHP Developers Network
http://forums.devnetwork.net/

Help to save Values with session in Swiftmailer
http://forums.devnetwork.net/viewtopic.php?f=1&t=137349
Page 1 of 1

Author:  bennot [ Tue Feb 05, 2013 3:35 am ]
Post subject:  Help to save Values with session in Swiftmailer

Hello,



The Form is sending a PDF via DOMPDF to the entered email adress. When i submit the form and a field isn't fieled up -> the page reload with error message and all the selections and entries are lost.!!! :(

I know i can fix this with $session and $variables to save the entered details in the form. But i am php newbee and dont get it to work :( i tried to get it from this tutorial (viewtopic.php?t=62993)


can some one help me with this code please.

Syntax: [ Download ] [ Hide ]
<?php
if (!empty($_POST)) {

        // Used for later to determine result
        $success = $error = false;

        // Object syntax looks better and is easier to use than arrays to me
        $post = new stdClass;
       
        // Usually there would be much more validation and filtering, but this
        // will work for now.
        foreach ($_POST as $key => $val)
                $post->$key = trim(strip_tags($_POST[$key]));
               
        // Check for blank fields
        if ( empty($post->gender) OR empty($post->name) OR empty($post->name2) OR empty($post->strasse) OR empty($post->hausnummer)  OR empty($post->plz)  OR empty($post->hausnummer) OR empty($post->telefon) OR empty($post->email)  OR empty($post->about) OR empty($post->agb))
                $error = true;

        else {

                // Get this directory, to include other files from
                $dir = dirname(__FILE__);
               
                // Get the contents of the pdf into a variable for later
                ob_start();
                require_once($dir.'/pdf.php');
                $pdf_html = ob_get_contents();
                ob_end_clean();
               
                // Load the dompdf files
                require_once($dir.'/dompdf/dompdf_config.inc.php');
               
                $dompdf = new DOMPDF(); // Create new instance of dompdf
                $dompdf->load_html($pdf_html); // Load the html
                $dompdf->render(); // Parse the html, convert to PDF
                $pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
               
                // Get the contents of the HTML email into a variable for later
                ob_start();
                require_once($dir.'/html.php');
                $html_message = ob_get_contents();
                ob_end_clean();
               
                // Load the SwiftMailer files
                require_once($dir.'/swift/swift_required.php');

                $mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer

                $message = Swift_Message::newInstance()
                                       ->setSubject('subject') // Message subject
                                           ->setTo(array('123@gmail.com', $post->email  => $post->name)) // Array of people to send to
                                           ->setFrom(array('456@gmail.com' => 'name')) // From:
                                           ->setBody($html_message, 'text/html') // Attach that HTML message from earlier
                                           ->attach(Swift_Attachment::newInstance($pdf_content, 'myPDF.pdf', 'application/pdf'));
                                           
                                           
                                            // Attach the generated PDF from earlier
               
                // Send the email, and show user message
                if ($mailer->send($message)
               
               
                )
                        $success = true;
                       
                else
                        $error = true;
               
        }

}
?>

Author:  bennot [ Tue Feb 05, 2013 12:45 pm ]
Post subject:  Re: Help to save Values with session in Swiftmailer

no ideas?

Author:  requinix [ Tue Feb 05, 2013 3:31 pm ]
Post subject:  Re: Help to save Values with session in Swiftmailer

Not after 9 hours, no.

Where is the code for the form? That's (apparently) where the problem is.

Author:  Weirdan [ Tue Feb 05, 2013 5:09 pm ]
Post subject:  Re: Help to save Values with session in Swiftmailer

This has nothing to do with SwiftMailer => moving to PHP Code

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/