PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 16, 2017 2:21 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Feb 05, 2013 3:35 am 
Offline
Forum Newbie

Joined: Tue Feb 05, 2013 3:26 am
Posts: 3
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;
               
        }

}
?>


Top
 Profile  
 
PostPosted: Tue Feb 05, 2013 12:45 pm 
Offline
Forum Newbie

Joined: Tue Feb 05, 2013 3:26 am
Posts: 3
no ideas?


Top
 Profile  
 
PostPosted: Tue Feb 05, 2013 3:31 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6606
Location: WA, USA
Not after 9 hours, no.

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


Top
 Profile  
 
PostPosted: Tue Feb 05, 2013 5:09 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
This has nothing to do with SwiftMailer => moving to PHP Code


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group