php and monthly newsletter automation?
Moderator: General Moderators
php and monthly newsletter automation?
i have a mail() function message i would like to send to a list of users out of a mysql database. this is normally easy to do, i just do a while and for each email it pulls out of database i use the mail()function. but i would like to have this done automatically say every monday at 1pm without me pulling the page up in a browser. i have tried using windows scheduled task by running a batch file with "c:\xampp\php\php.exe -f c:\xampp\htdocs\mailer.php" in it which points to my code and set tp run every monday at 1. but it does not send. i use windows and i have smtp setup in php.ini to send email. when the code is run as a scheduled task it doesnt work, but when run in internet explorer normally, it does. how do you send automated email with php, no other language. help me get in the right direction with it please
- markusn00b
- Forum Contributor
- Posts: 298
- Joined: Sat Oct 20, 2007 2:16 pm
- Location: York, England
Re: php and monthly newsletter automation?
Are you positive the task is being executed? Do you receive any errors?
Re: php and monthly newsletter automation?
nm this
Last edited by rctrimble on Sat Oct 24, 2009 9:17 pm, edited 1 time in total.
Re: php and monthly newsletter automation?
ok if anyone is reading this ignore my previous emails. i have it working somehow its able to send to my test emails at @gmail.com, @comcast.net without any problems. but its not working with @yahoo.com it appears as a blank email only below is my code i am using to send the email. if you know why its appearing blank on yahoo.com please let me know
Code: Select all
<?php
include("C:/xampp/htdocs/ggggg/connectionGT2.php");
mysql_connect('localhost', $user, $pass) or die("connection failed." . mysql_error());
mysql_select_db($db) or die("query failed " . mysql_error());
$query = "select * from users";
$result = mysql_query($query) or die("query failed." . mysql_error());
while($row = mysql_fetch_array($result))
{
if($row['mail_list']=="yes"){
$to = $row['user_email'];
$subject = 'ggggggg auto-email';
$random_hash = md5(date('r', time()));
$headers = "From: webmaster@gggggggg.com\r\nReply-To: webmaster@gggggggg.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php include('testfile.txt');?>
<?php include('testfile2.txt');?>
<hr />You can unsubscribe at anytime by logging into your ggggggg account and navigating to -> Members -> Account, or by clicking <a href='http://gggggggg/members/unsubscribe.php?email=<?php echo $to;?>'>here</a>.<br />Note* some email clients and/ or servers will truncate this emil in that case visit <a href='http://gggggggg'>gggggggggg.com</a> and be sure to use the browse function<br /><br />
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
mail( $to, $subject, $message, $headers );
}}
mysql_close() or die("disconnect failed " . mysql_error());
?>