Help to save Values with session in Swiftmailer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bennot
Forum Newbie
Posts: 3
Joined: Tue Feb 05, 2013 2:26 am

Help to save Values with session in Swiftmailer

Post by bennot »

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.

Code: Select all

<?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;
		
	}

}
?>
bennot
Forum Newbie
Posts: 3
Joined: Tue Feb 05, 2013 2:26 am

Re: Help to save Values with session in Swiftmailer

Post by bennot »

no ideas?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help to save Values with session in Swiftmailer

Post by requinix »

Not after 9 hours, no.

Where is the code for the form? That's (apparently) where the problem is.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Help to save Values with session in Swiftmailer

Post by Weirdan »

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