westmatrix99
02-24-2007, 09:47 PM
How to send an entire dynamic web page using phpmail()?
Similar to mail this page or send to a freind link
Similar to mail this page or send to a freind link
|
||||
How to send an entire web page using phpmail()?westmatrix99 02-24-2007, 09:47 PM How to send an entire dynamic web page using phpmail()? Similar to mail this page or send to a freind link Fou-Lu 02-25-2007, 03:25 AM Errr.... seems like this thread is incomplete. Probably just have to send an appropriate header with it. text/html should do it. westmatrix99 02-25-2007, 06:11 AM Not sure what you mean. Where does that stuff go or how should it look? I have some code but have nothing for the body section. westmatrix99 02-25-2007, 06:36 AM Why is it incomplete? flann 02-25-2007, 07:08 AM here is a mail function that i use all the time. You can put all the html into a variable ($html in my example). $html = "<p>Put your html in this variable</p>"; $email = "name@domain.com"; // who it is to $subject = "Subject"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: Name <name@domain.com>\r\n"; mail($email,$subject,$html,$headers); westmatrix99 02-25-2007, 07:16 AM Cool thanks, but then it's not a dynamic page, which means for every page I send it has to hand coded. Mhtml 02-25-2007, 07:49 AM Umm.. Just assign some dynamic markup to the $html variable? How about (really dirty example code): class email{ private $to, $subj, $msg, $headers; public function __construct($to=null,$subj=null,$msg=null,$headers=null){ if(!$to || !$subj || !$msg){ throw new Exception("Email instance requires to, subject and message data."); } $this->to = $to; $this->subj = $subj; $this->msg = $msg; $this->headers = $headers; } public function send(){ if(!mail($this->to, $this->subj, $this->msg, $this->headers)){ throw new Exception("Email could not be sent"); } return 1; } } class template{ private static $vars = null; private static $vars_set = false; public static $silent = true; public function __construct(){ throw new Exception("Instances of template are not allowed"); } public function __clone(){ throw new Exception("Cloning of template is not allowed"); } public function import($filename=null){ if(!$filename){ if(!self::$silent){ throw new Exception("Expecting filename, received NULL"); } return;//exit silently } if(!file_exists($filename)){ if(!self::$silent){ throw new Exception("Unable to load template with filename '$filename', no file exists"); } return;//exit silently } $eOld = ""; if(self::$silent){ $eOld = error_reporting(0);//disable error reporting if silent mode } ob_start(); include($filename); $content = ob_get_contents(); ob_end_clean(); if(self::$silent){ error_reporting($eOld);//enable error reporting again } return $content; } } $mail = new email("foo@bar.com", "subject", template::import("foo.php"), "Content-type: text/html"); $mail->send(); There's probably errors and stuff through it, sort of hacked it together and it's not tested.. But shouldn't be too hard to move on. westmatrix99 02-25-2007, 11:45 AM What about security? Does this script at leat give some secure features? A bad-intentioned person could use: http://www.my.page.com/sendme.php?page=http://www.nicesite.com And will have a password sent to email: http://www.my.page.com/sendme.php?page=/etc/passwd cheers Mhtml 02-25-2007, 11:48 AM Well that's up to you. What I (and flann) gave you leaves it to you to decide how and what is sent, it just provides a method to do so. GJay 02-25-2007, 12:01 PM 'send to a friend' links normally just send a link to the page, rather than the page itself. Does yours really have to be different? westmatrix99 02-25-2007, 12:02 PM Ok this what I got: Is this correct? <?php class email{ private $to, $subj, $msg, $headers; public function __construct($to=null,$subj=null,$msg=null,$headers=null){ if(!$to || !$subj || !$msg){ throw new Exception("Email instance requires to, subject and message data."); } $this->to = $to; $this->subj = $subj; $this->msg = $msg; $this->headers = $headers; } public function send(){ if(!mail($this->to, $this->subj, $this->msg, $this->headers)){ throw new Exception("Email could not be sent"); } return 1; } } class template{ private static $vars = null; private static $vars_set = false; public static $silent = true; public function __construct(){ throw new Exception("Instances of template are not allowed"); } public function __clone(){ throw new Exception("Cloning of template is not allowed"); } public function import($filename=null){ if(!$filename){ if(!self::$silent){ throw new Exception("Expecting filename, received NULL"); } return;//exit silently } if(!file_exists($filename)){ if(!self::$silent){ throw new Exception("Unable to load template with filename '$filename', no file exists"); } return;//exit silently } $eOld = ""; if(self::$silent){ $eOld = error_reporting(0);//disable error reporting if silent mode } ob_start(); include($filename); $content = ob_get_contents(); ob_end_clean(); if(self::$silent){ error_reporting($eOld);//enable error reporting again } return $content; } } $mail = new email("example.com", "TEST HTML", template::import("http://www.furkids.co.za/index.php"), "Content-type: text/html"); $mail->send(); ?> westmatrix99 02-25-2007, 12:04 PM Hi GJay The problem that I have seen befor is HTTPREFER errors in PHP. westmatrix99 02-25-2007, 12:08 PM This is an error I got after runnin the script above: Fatal error: Uncaught exception 'Exception' with message 'Email instance requires to, subject and message data.' in c:\Inetpub\wwwroot\usermail\mail3.php:6 Stack trace: #0 c:\Inetpub\wwwroot\usermail\mail3.php(57): email->__construct('info@furkids.co...', 'TEST HTML', NULL, 'Content-type: t...') #1 {main} thrown in c:\Inetpub\wwwroot\usermail\mail3.php on line 6 westmatrix99 02-25-2007, 12:20 PM Hi flann If I use your one I get this in email. http://www.furkids.co.za/index.php <?php //$html = "<p>Put your html in this variable</p>"; $html = "http://www.furkids.co.za/index.php"; $email = "example.com"; // who it is to $subject = "Subject"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: Info <example.com>\r\n"; mail($email,$subject,$html,$headers); ?> Cheers westmatrix99 02-25-2007, 12:25 PM Hi guys First of all thanks for your responses. Here is what mine looks like. <?php $page = "http://www.domain.com/"; $buffer = ""; $handle = fopen($page, "r"); if ($handle) { while (!feof($handle)) { $buffer .= fgets($handle, 4096); } fclose($handle); } require('class.phpmailer.php'); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = 'localhost'; $mail->From = 'mail@domain.com'; $mail->FromName = 'Name'; $mail->AddBCC ('mail@domain.com', 'Name'); $mail->AddReplyTo('mail@domain.com', 'Name'); // optional name $mail->WordWrap = 50; // set word wrap to 50 characters //$mail->AddAttachment('image.jpg','Name'); // optional name $mail->IsHTML(true); // set email format to HTML $mail->Subject = 'HTML Test'; $mail->Body = $buffer; //$mail->AltBody = ''; //this is for text no HTML if(!$mail->Send()) { echo 'Message could not be sent. <p>'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo 'Message has been sent'; ?> Please make sure to have the class.phpmailer.php I think you can get from php.net using phpmail. Cheers |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum