PDA

View Full Version : Need Help in PHP Script for Cron Job



acheron
06-17-2007, 03:57 PM
Hey,

I'm very new to PHP and I was just wondering if any of you can help me with this.
I already added the code below in the cron jobs page but it won't seem to run it. Existing php scripts in cron seem to be working fine.
I'm not sure if there's anything wrong with the code. Please do help me. Thanks for your time!


<?php
ob_start();

// prevent client-side caching: must be called before displaying any output/html headers
header("Expires: Sat, 22 Jul 1978 15:00:00 GMT"); // Any date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0

require_once('configuration.php');
$conn = mysql_connect($mosConfig_host, $mosConfig_user, $mosConfig_password) or die(mysql_error());
mysql_select_db($mosConfig_db, $conn) or die(mysql_error());

function sendEmail($email, $firstName) {
$subject = "Your Request";

$message = read_file("templates/net/email.php");
$message = str_replace("{$name}", $firstName, $message);
$message = str_replace("\n.", "\n..", $message);

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: service@net.com' . "\r\n";

return mail($email, $subject, $message, $headers);
}


?>
<html>
<head>
<title>Send To Garden</title>
</head>
<body>
<?php

sendEmail("trial@trial.com", "trial");

?>
</body>
</html>
<?php
ob_end_flush();
?>


cheers,
acheron

acheron
06-17-2007, 05:33 PM
Is it possible to send emails through cron? It works when i just access it in the address bar.. :confused:

Any ideas? Maybe there are some configurations I have to do? :(

charlesgan
06-17-2007, 09:19 PM
there is email command directly from cron.
take a look at this as well
http://www.webmasterworld.com/forum40/1383.htm

oo. also found this cron email plugin
http://expressionengine.com/downloads/details/cron_send_email/

Pethens
06-18-2007, 07:59 PM
I have sent email using PHP from a cron job without any problems. Try running your script from the command line to see if you get any error messages.