Current location: Hot Scripts Forums » Programming Languages » PHP » View Source of an web page


View Source of an web page

Reply
  #1 (permalink)  
Old 07-05-04, 05:40 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
View Source of an web page

I'm making a php send a web page system and wanted to know how I can get the source to a var so i can put that into mail()


Is this possiable? If not what is the best way?
Reply With Quote
  #2 (permalink)  
Old 07-05-04, 07:51 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Just send it as an attachment if it is a local file. See www.php.net/mail on how to handle attachements.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #3 (permalink)  
Old 07-06-04, 02:40 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah I thought about that but I would really like to send the page.

The page is a newsletter constructed from MySql, its a little complicated to to put into a var then to mail() func. I've seen a system where you can send a web page and thought its probably must be a way of getting the source from a page.

Anyone else have any ideas please let me know.
Reply With Quote
  #4 (permalink)  
Old 07-06-04, 03:00 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
You got to love PHP,

just found this snipet that does the trick

PHP Code:

<?php 

  $file 
file('http://www.yahoo.com'); 
   
  
$i 1
  foreach(
$file as $line) { 
    
$line htmlspecialchars($line); 
    echo(
"<b>$i</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"$line ."<br />\n"); 
    
$i++; 
  } 
?>
Reply With Quote
  #5 (permalink)  
Old 07-06-04, 04:32 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
ok, sending a html through php works cool. I tried to replace where the html go with $line var but it dont seem to work. Any ideas guys?

PHP Code:

<?PHP


//add From: header 
$headers "From: [email]info@email.com[/email]\n"

//specify MIME version 1.0 
$headers .= "MIME-Version: 1.0\n"

//unique boundary 
$boundary uniqid("HTMLDEMO"); 

//tell e-mail client this e-mail contains//alternate versions 
$headers .= "Content-Type: multipart/alternative" 
   
"; boundary = $boundary\n\n"

//message to people with clients who don't 
//understand MIME 
$headers .= "This is a MIME encoded message.\n\n"

//plain text version of message 
$headers .= "--$boundary\n" 
   
"Content-Type: text/plain; charset=ISO-8859-1\n" 
   
"Content-Transfer-Encoding: base64\n\n"
$headers .= chunk_split(base64_encode("This is the plain text version!")); 

//HTML 
$headers .= "--$boundary\n" 
   
"Content-Type: text/html; charset=ISO-8859-1\n" 
   
"Content-Transfer-Encoding: base64\n\n";

$file file('http://www.yahoo.com'); 
  
  foreach(
$file as $line
  { 
  
$line htmlspecialchars($line); 
  
$headers .= chunk_split(base64_encode("$line"));
  }     

//send
mail("info@feneo.com""An HTML Message"""$headers); 

        
?>
what ya think?
Reply With Quote
  #6 (permalink)  
Old 07-06-04, 10:38 AM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Here are some functions I found for sending multipart emails. Always works for me.

PHP Code:

?php

/*$to_name = 'Joe Bloggs';
$to_email = 'joe@joesemail.com';
$from_name = 'Your Name';
$from_email = 'you@youremail.com';
$subject = 'mail Subject';
$body_simple = 'Simple content for non-MiME-compliant clients';
$body_plain = 'Plain text content';
$body_html = '<html><head></head><body>HTML content</body></html>';

echo api_email($to_name, $to_email, $from_name, $from_email,
$subject, $body_simple, $body_plain, $body_html);
*/

// MIME email
function api_email($to_name$to_email$from_name$from_email,
$subject$body_simple$body_plain$body_html)
{
    
$boundary api_password(16);
    
$headers "From: \"".$from_name."\" <".$from_email.">\n";
    
$headers .= "To: \"".$to_name."\" <".$to_email.">\n";
    
$headers .= "Return-Path: <".$from_email.">\n";
    
$headers .= "MIME-Version: 1.0\n";
    
$headers .= "content-type: multipart/alternative; boundary=\"".$boundary."\"\n\n";
    
$headers .= $body_simple."\n";
    
$headers .= "--".$boundary."\n";
    
$headers .= "content-type: text/plain; charset=ISO-8859-1\n";
    
$headers .= "Content-Transfer-Encoding: 8bit\n\n";
    
$headers .= $body_plain."\n";
    
$headers .= "--".$boundary."\n";
    
$headers .= "content-type: text/HTML; charset=ISO-8859-1\n";
    
$headers .= "Content-Transfer-Encoding: 8bit\n\n";
    
$headers .= $body_html."\n";
    
$headers .= "--".$boundary."--\n";

    
mail(''$subject''$headers);

}

// Generate random alphanumeric password
function api_password($length 8)
{
    
srand((double) microtime() * 1000000);
    
$alpha = array('a','b','c','d','e','f','g','h','i','j','k','l',
    
'm','n','o','p','q','r','s','t','u','v','w','x','y','z');
    
$options = array('alpha','number');

    for (
$i 0$i $length$i++)
    {
        
$char array_rand($options,1);
        if (
$options[$char] == 'alpha')
        {
            
$random_letter rand (0,25);
            
$password .= $alpha[$random_letter];
        }
        else
        {
            
$random_number rand (0,9);
            
$password .= $random_number;
        }
    }
    return 
$password;

__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #7 (permalink)  
Old 07-06-04, 11:28 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Hey,

The html email works fine just that I'm trying to do it with html from a selected website. Frinding the source of a website then send that as a multipart email. Have a look at the code i pasted up.. and the other posts, you'll see where I'm getting at..
Reply With Quote
  #8 (permalink)  
Old 07-06-04, 12:01 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
I would do an echo on $headers to see what you are sending is right then work backwards from that.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #9 (permalink)  
Old 07-07-04, 05:04 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
I worked it out.

All it is this:

PHP Code:

<?PHP


//add From: header 
$headers "From: [email]email@email.com[/email]\n"

//specify MIME version 1.0 
$headers .= "MIME-Version: 1.0\n"

//unique boundary 
$boundary uniqid("HTMLDEMO"); 

//tell e-mail client this e-mail contains//alternate versions 
$headers .= "Content-Type: multipart/alternative" "; boundary = $boundary\n\n"

//message to people with clients who don't 
//understand MIME 
$headers .= "This is a MIME encoded message.\n\n"

//plain text version of message 
$headers .= "--$boundary\n" "Content-Type: text/plain; charset=ISO-8859-1\n" "Content-Transfer-Encoding: base64\n\n"

$headers .= chunk_split(base64_encode("This is the plain text version!")); 

//HTML 
$headers .= "--$boundary\n" "Content-Type: text/html; charset=ISO-8859-1\n" "Content-Transfer-Encoding: base64\n\n";
   
$file file('http://www.yahoo.com');

foreach(
$file as $line
  { 
    
$html .= $line;
  }
  
 
$headers .= chunk_split(base64_encode("$html"));

echo 
$html;

//send
mail("email@email.com""An HTML Message"""$headers); 

        
?>
Have " and ' may cause problems with sending a page. I'm sure there is a way of getting pass that. Well here it is.. Sending a web page system
Reply With Quote
  #10 (permalink)  
Old 07-07-04, 06:02 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
how about saving some memory and execution time by changing this:
PHP Code:

$file file('http://www.yahoo.com');


foreach(
$file as $line)
  {
    
$html .= $line;
  } 
to this:
PHP Code:

$html file_get_contents('http://www.yahoo.com'); 


but you need PHP 4.3.0 or higher to use file_get_contents()
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Special Hosting Offers From SiSHCO! Very Hot! SiSHCO General Advertisements 0 06-09-04 01:10 PM
Is it Possible to export data from a web page with no admin access to mySQL? phpseth PHP 1 06-04-04 10:58 AM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 05:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.