View Source of an web page
07-05-04, 05:40 PM
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?
07-05-04, 07:51 PM
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
07-06-04, 02:40 AM
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.
07-06-04, 03:00 AM
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
07-06-04, 04:32 AM
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?
what ya think?
07-06-04, 10:38 AM
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
07-06-04, 11:28 AM
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..
07-06-04, 12:01 PM
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
07-07-04, 05:04 AM
Coding Addict
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
I worked it out.
All it is this:
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
07-07-04, 06:02 AM
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:
to this:
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 ]
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off