Jump to content

PHP Grab <body> send mail


kongowea

Recommended Posts

Hi,

Please assist me with  a PHP code that can capture a displayed HTML body and mail it to a specific email account.

 

Hint: I tried to capture the page using grabURL function though since the page is secured, the recipient is forwarded a login page, but not the displayed page

 

The class I used is:

<?php
class grabUrl{
var $toEmail="";
var $mailSubject="";
var $mailHeaders="";
var $addHeaders="";
var $grabData="";

function createTo($email){
	$this->toEmail=$email;
}

function createCC($email){
	$this->mailHeaders.="Cc: $email\r\n";
}

function createBCC($email){
	$this->mailHeaders.="Bcc: $email\r\n";
}

function createSubject($sub){
	$this->mailSubject=$sub;
}

function createFrom($name,$email){
	$this->mailHeaders.="From: '$name' <$email>\r\n";
}

function sendMail($charset="iso-8859-1"){
	$this->mailHeaders.="MIME-Version: 1.0\r\n";
	$this->mailHeaders.="Content-type: text/html; charset=$charset\r\n"; // alternate is utf-8
	if(mail($this->toEmail,$this->mailSubject,$this->grabData,$this->mailHeaders)){
		return true;
	}else{
		return false;
	}
}

function getData($url,$use_include_path=0){
	$file = @fopen($url, 'rb', $use_include_path);
	if ($file){
		if ($fsize = @filesize($filename)){
			$data = fread($file, $fsize);
			}else{
				while (!feof($file)){
					$data .= fread($file, 1024);
			}
		}
	fclose($file);
	}
	$this->grabData=$data;
}

function showPage(){
	echo $this->grabData;
}

function returnData(){
	return $this->grabData;
}


}

/*
Sample Usage
*/

/*
$foo=new grabUrl();
$foo->createTo("xxx@xxx.com");
$foo->createCC("xxx@qqq.com");
$foo->createBCC("xxx.www.com");
$foo->createFrom("Vedanta Barooah","xxx@ssss.com");
$foo->createSubject("This is a test mail! Please Ignore!");
$foo->getData("http://www.bbc.co.uk");
if($foo->sendMail()){
echo "Mail Sent!";
}else{
echo "Error Sending Mail!";
}
*/
?>

 

Below is the code that calls the above class

<?

include("sendMail.php");
$foo=new grabUrl();
$foo->createTo("kongowea@ppp.com");
$foo->createCC("kongowea@ccc.com");
$foo->createFrom("kongowez@rrrr.com");
$foo->createSubject("My trial");
$foo->getData("http://www.phpfreaks.com/forums/index.php");
if($foo->sendMail()){
echo "Mail Sent!";
}else{
echo "Error Sending Mail!";
}
?>

 

Regards

Kongowea

 

Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.