Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question How to send an entire web page using phpmail()?

    How to send an entire dynamic web page using phpmail()?

    Similar to mail this page or send to a freind link
    Last edited by westmatrix99; 02-24-2007 at 10:00 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Errr.... seems like this thread is incomplete.

    Probably just have to send an appropriate header with it. text/html should do it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Why is it incomplete?
    Thanks for you support!

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here is a mail function that i use all the time. You can put all the html into a variable ($html in my example).

    PHP Code:
        $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); 

  • #6
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Cool thanks, but then it's not a dynamic page, which means for every page I send it has to hand coded.

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Umm.. Just assign some dynamic markup to the $html variable?
    How about (really dirty example code):
    PHP 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;
            }
            
        } 
    PHP Code:
    $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.
    Last edited by Mhtml; 02-25-2007 at 07:51 AM.
    Omnis mico antequam dominus Spookster!

  • #8
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    What about security?
    Does this script at leat give some secure features?

    A bad-intentioned person could use:
    And will have a password sent to email:
    cheers
    Thanks for you support!

  • #9
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Omnis mico antequam dominus Spookster!

  • #10
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    '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?
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #11
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Ok this what I got:
    Is this correct?

    PHP Code:
    <?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();  
    ?>
    Last edited by marek_mar; 04-01-2007 at 09:23 PM.
    Thanks for you support!

  • #12
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi GJay
    The problem that I have seen befor is HTTPREFER errors in PHP.
    Thanks for you support!

  • #13
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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
    Thanks for you support!

  • #14
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi flann
    If I use your one I get this in email.
    Code:
    <?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
    Last edited by marek_mar; 04-01-2007 at 09:23 PM.
    Thanks for you support!

  • #15
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Post

    Hi guys
    First of all thanks for your responses.
    Here is what mine looks like.
    Code:
    <?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
    Last edited by westmatrix99; 02-25-2007 at 09:08 PM.
    Thanks for you support!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •