?
Solved

ob_get_clean();

Posted on 2012-03-15
3
Medium Priority
?
331 Views
Last Modified: 2012-03-18
The code attached below works. An html email message is sent in the function called display_email(); using this code:
ob_start();
display_email();
$msg .= ob_get_clean();

I have constructed the actual message in a function as the email contained quite a bit of dynamic informaion and it seemed to be the only way I could get the email to send its content.

My question relates to an errror I recieve in de bug mode that states that the variable $msg is undefined. My code works, everying seems to function just fine hower I would preref to figure out what the undefined $msg variabke is all about. Especially as the $msg is there when it pop out as an email message.
Thanks,
N
$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				$headers .= "Reply-To: ".$_POST['fp']['Contact Email Address'][0]." \r\n";
				$headers .= "From: ".$_POST['fp']['Contact Email Address'][0]."\r\n";
				
           // Send
                $subject = $_POST['subject'];
           		$to      = "someemail@somedoman.com" ;
			
		
ob_start(); 
display_responce($_POST['heading'], $_POST['subject'], $_POST['fp'], $_POST['sf']);
$msg .= ob_get_clean(); 
 
        mail($to, $subject, $msg, $headers);

Open in new window

0
Comment
Question by:Neil_Bradley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1000 total points
ID: 37727985
$msg .= ob_get_clean();

That uses the '.' syntax for concatenating something onto a string.  Just put $msg = ""; near the beginning of your page and then it will be defined.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 37728666
Unlike PHP's habit of creating an array when you use the "append" notation, PHP does not create a string when you use the "append" notation. Instead it raises a Notice when you attempt to append to an undefined string, then it creates the string using the content you asked for.  It is an annoying inconsistency in the language.  You can predefine your string variables like DaveBaldwin suggested (and that is my preferred way to handle this situation).  You can suppress the Notice with this.

error_reporting(E_ALL ^ E_NOTICE);

That is the default PHP error reporting setting.  I prefer to see the Notice messages because it usually means I have a typographical error!
// WORKS TO ADD A NEW ELEMENT TO THE END OF $x
// CREATES THE ARRAY $x IF IT DOES NOT ALREADY EXIST
// GIVES NO NOTICE THAT IT CREATED AN UNDEFINED VARIABLE
$x[] = 'Hello';

// WORKS TO ADD A STRING TO THE "END" OF VARIABLE $y
// CREATES THE STRING $y IF IT DOES NOT ALREADY EXIST
// RAISES A NOTICE ABOUT AN UNDEFINED VARIABLE
$y .= 'Hello';

Open in new window

0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 37735331
Thanks  Dave an Ray, between you, you have solved and answered my question thoroughly. I am pleased to resolve the $msg .= ob_get_clean(); issue as its the only way I have found to send an email containing code other than simple echoed  strings.
Cheers,
N
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question