Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WAMP - Automatically send webpage

Status
Not open for further replies.

hunterdw

Technical User
Oct 25, 2002
345
0
0
US
Howdy--

I have a WAMP installation - Server 2003, PHP4, MySQL5, Apache2

I need the ability to send the contents of a webpage to a particular set of email addresses each night about 10pm.

The webpage contents are
you can see that vm = month, vd = date and vy = year

I need to be able to somehow do this:

a) find the date
b) pass the right variables
c) bring up the webpage
d) send the contents to several email addresses

I know at one time you could do windows scheduler to run php.exe -q something.php and it would launch that page.

How would I script the rest of it?

Anyone?

--DW
 
Code:
$month = date("m");
$year = date("Y");
$day = date("d");
$url = "[URL unfurl="true"]http://www.domain.com/nightly_email.php?showall=yes&vm={$month}&vd={$day}&vy={$year}";[/URL]

$fh = fopen($url, "rb") or die("cannot get contents from remote site");
$contents = stream_get_contents($fh);
fclose($fh);

$addresses[] = "firstemail@domain.com";
$addresses[] = "secondemail@domain.com";
$from = "youremailaddress@address.com";
$subject = "nightly email message";
$headers = "From: $from\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

set_time_limit(0); 
foreach ($addresses as $address):
 mail($to, $subject, $content, $headers);
endforeach;

assuming you are using windows you just use the task scheduler and point it to the php cli and pass the script name. i.e. c:\php\php-win.exe scriptname.php
 
Yes, I agree. But how would I script the rest of it (the date).

Here's what I wrote: "I know at one time you could do windows scheduler to run php.exe -q something.php and it would launch that page. How would I script the rest of it?"

==DW
 
i read what you wrote!

does the script i provided above not do what you want?
 
no, the script doens't do anything.

I run PHP4 and don't have php-win.php

But, I tried it with just php.exe and it runs without errors, but it doesn't send email

any other PHP script with the mail() function sends email just great.

Sorry I missed your script up there the first time. I read it on my blackberry on my way to the office and just saw your text, not the script itself.
 
sorry - shonky error checking by me (although it would never have worked on php4)

try this instead

Code:
<?
$month = date("m");
$year = date("Y");
$day = date("d");

$url = "[URL unfurl="true"]http://www.domain.com/nightly_email.php?showall=yes&vm={$month}&vd={$day}&vy={$year}";[/URL]
$contents = "";
$fh = fopen($url, "rb") or die("cannot get contents from remote site");
while (!feof($fh)) {
  $contents .= fread($fh, 8192);
}
fclose($fh);

$addresses[] = "firstemail@domain.com";
$addresses[] = "secondemail@domain.com";
$from = "";
$subject = "nightly email message";
$headers = "From: $from\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

set_time_limit(0); 
foreach ($addresses as $address):
 mail($address, $subject, $contents, $headers) or die("error sending mail";
endforeach;


?>
 
same result... runs without errors, but doesn't send email

nothing in spam queue

nothing in undeliverable

thanks though
 
not sure why you are not getting a result.

i have put a version up on my server. you can test it as you want. remember to put the url in as " (i.e. it must have the http bit).

the link is
the code for this is
Code:
<?
/*
$month = date("m");
$year = date("Y");
$day = date("d");

$url = "[URL unfurl="true"]http://www.domain.com/nightly_email.php?showall=yes&vm={$month}&vd={$day}&vy={$year}";[/URL]

*/
$url = isset($_POST['url']) ? $_POST['url'] : "";
$address = isset($_POST['address']) ? $_POST['address'] : "";

if (isset($_POST['submit'])):
	$contents = "";
	$fh = fopen($url, "rb") or die("cannot get contents from remote site");
	while (!feof($fh)):
	  $contents .= fread($fh, 8192);
	endwhile;
	fclose($fh);
	
	/*
	$addresses[] = "firstemail@domain.com";
	$addresses[] = "secondemail@domain.com";
	*/
	$from = "********";
	$subject = "nightly email message";
	$headers = "From: $from\r\n" .
		   'X-Mailer: PHP/' . phpversion() . "\r\n" .
		   "MIME-Version: 1.0\r\n" .
		   "Content-Type: text/html; charset=utf-8\r\n" .
		   "Content-Transfer-Encoding: 8bit\r\n\r\n";
	
	set_time_limit(0); 
	// foreach ($addresses as $address):
		if (mail($address, $subject, $contents, $headers)):
	 		$msg= "Mail sent ";
		else:
			die("error sending mail");
		endif;
	// endforeach;
endif;

?>
<head>
<style type="text/css">
.wrapper {width: 350px;}
body, input {font-family:"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; font-size:11px;}
.row {clear:both;}
.spacer {font-size:2px; line-height:1px; clear:both;}
.label {width: 150px; float:left; padding-right: 5px; text-align:right;}
.field {width: 180px; float:left; padding-left: 2px; text-align:left;}
.field input[type="text"] {width: 90%;}
.button {margin-right:40px; float:right; }
</style>
</head>
<body>
<div class="wrapper">
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<div class="row">
<span class="label">Type the url here</span>
<span class="field"><input type="text" name="url" value="<?=$url?>" /></span>
</div>
<div class="row">
<span class="label">Enter your email address</span>
<span class="field"><input type="text" name="address" value="<?=$address?>" /></span>
</div>
<div class="spacer">&nbsp;</div>
<span class="button"><input type="submit" name="submit" value="send email" /></span>
<div class="spacer">&nbsp;</div>
</form>
</div>
<hr/>
<?=$msg?>
</body>
 
How does it work?

I type in a URL and get "cannot get contents from remote site"

---DW
 
try typing in as an example.

it works for me just fine. it could that the url that you are requesting is requiring some form of cookie or other security. what is the url?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top