[RESOLVED] ?outputbuffer? with mail(file_get_contents)!
With the script given to me by SambaNeko I can do this...
PHP Code:
$to = "[email protected]";
$subject = "This awesome website";
$message = file_get_contents('http://www.example.com');
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
...send a php page to an email address!
Unfortunitly If my PHP page has...
PHP Code:
?x=&y= //used to pull selected info from the server
...it doesn't get recorded?! I have been directed to using a outputbuffer to record and send the information but I have been warned that these can have a negative effect on the server if used incorrectly.:eek:
I have the URL starting with '?x=' stored in a variable ('$URLstring') how can I edit the code at the top to send the page with the Information stored?
Re: ?outputbuffer? with mail(file_get_contents)!
Do you mean the ?x=&y= are query string variables? (as in, "example.com/?x=&y=") As mentioned in the other thread, I tried this code on my homepage, which also uses query string variables to determine which content is shown, and it worked properly... and there's no output buffer on it.
Do you think you could post how you're using this code (with your site details in the code rather than examples)? Might help...
Re: ?outputbuffer? with mail(file_get_contents)!
The URL looks like this 'http://www.mysite.com/database/form.php?x=1&y=2' in the page i'm using $_GET['x'] to get the value - look for it on the SQL database and show the relevant information.
When I paste the URL in the code it picks up the page but doesn't show the information?
The page works on its own but when I send the file it doesn't keep the selected results from the database.
Re: ?outputbuffer? with mail(file_get_contents)!
Are your query string variables using a database or are is there another way I should try?
Re: ?outputbuffer? with mail(file_get_contents)!
It may seem like a dumb question, but have you tried viewing the page [that you're trying to email] in a browser? Does the content you want show up properly in that case?
I'm kind of at a loss to help here - I've tried a page that prints out query string vars directly, and I've tried one that takes the vars, grabs some database content based on them, and prints that out... both of these cases worked. Not trying to deny your problem, but I can't really address it if I can't replicate it...
Seeing the code of the page you're trying to send might be helpful.
Re: ?outputbuffer? with mail(file_get_contents)!
Here is a small clippit of the script.
PHP Code:
<?php
$lastname=$_GET['name'];
?><?php // connect to customer and work table
error_reporting(0);
$con = mysql_connect("Clients.db.xxxxxxx.hostedresource.com", "Clients", "PaSsWoRd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Clients", $con);
$query = mysql_query("SELECT * FROM DB WHERE lastname='$lastname'");
$site = mysql_fetch_assoc($query);
echo "$site['website']"."$site['lastname']"; // and other DB stuff
?>
HTML Code:
<input name="mailme" type="submit" value="Send" />
PHP Code:
<?php
if ($_POST['mailme']){
$to="[email protected]";
$subject="work";
$message = file_get_contents('http://www.site.com/online/preview.php?name=$lastname');
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$sent=mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your page was sent successfully"; }
else
{print "We encountered an error sending your page"; }
} ?>
<?php
ftp_close($con);
?>
I think I've receated it in a usable form! If you can transform it into something
that will send, Thanks.
Alternatively would it be better or possible to...
1. pull the information from the database.
2. $_Post them
3. $_Request them
4. print them?
Re: ?outputbuffer? with mail(file_get_contents)!
Well, two thoughts on what you've posted...
This one line looked weird to me, and PHP threw a parse error when I tried it:
Code:
echo "$site['website']"."$site['lastname']";
There's no need for the double quotes when you're just concatenating variables, but you may want a whitespace in between them...
Code:
echo $site['website']." ".$site['lastname'];
The other thing I noticed is that, on your second PHP block, you don't have $lastname defined prior to the file_get_contents() line. But that could be because this isn't the full code?..
Re: ?outputbuffer? with mail(file_get_contents)!
Do you think it'll work when I make the changes?
Re: ?outputbuffer? with mail(file_get_contents)!
there's only one way to find out! ;) try it and let us know.
Re: ?outputbuffer? with mail(file_get_contents)!
The page still appears in my email client without the information from the database
Re: ?outputbuffer? with mail(file_get_contents)!
oh. I really didn't even look closely at your earlier post at all. you really need to be careful about the types of strings (and the types of quotes) you're making. see the following:
PHP Code:
$helloworld = "goodbye world";
echo '$helloworld';
//echos: $helloworld
echo "$helloworld";
//echos: goodbye world
echo $hellworld;
//echos: goodbye world
then, look at the following line you have:
PHP Code:
$message = file_get_contents('http://www.site.com/online/preview.php?name=$lastname');
PHP interprets this URL as the following, literally: http://www.site.com/online/preview.php?name=$lastname, so this entire time your script has been trying to look up the last name "$lastname," which I'm sure doesn't exist!
just change to:
PHP Code:
$message = file_get_contents("http://www.site.com/online/preview.php?name=$lastname");
Re: ?outputbuffer? with mail(file_get_contents)!
OK Its working now, in part? if the URL string has ...php?items[0]=&items[1]=... It looks like I cann't use this type of array?
Thanks for your help
Re: ?outputbuffer? with mail(file_get_contents)!
Oops Sorry It seems to be working Great now
Thanks.