champoi Posted December 30, 2008 Share Posted December 30, 2008 well, i'm creating an auto mailing script that emails the user (even when not logged in) by his chosen mode of update (, daily or by some other form), if for example the user chooses that every monday he should recieve an email about something, how do i trigger the mailer? i have an idea where in a mail trigger script is every page of the site, where in if any of the pages were viewed, the mailer is then triggered, checks if there are any mails to be sent then sends it. but i think this might slow down the page cause the whole process is repeated every time someone views the site. does anyone have an idea how? or is mine good enough, Quote Link to comment https://forums.phpfreaks.com/topic/138820-auto-mail-for-updates/ Share on other sites More sharing options...
ucffool Posted December 30, 2008 Share Posted December 30, 2008 If you also have a low number of visitors, that causes issues as well (besides the extra overhead). See if your webhost (I use dreamhost, they can do this) supports cronjobs. These are scheduled actions, such as running a php file. You could have that run daily or hourly, and make a specific file that will run the checks and email processing. I use it to do maintenance on a cache, uploads, and old items on one of my sites. There are more complex methods, but this is the simplest approach. Quote Link to comment https://forums.phpfreaks.com/topic/138820-auto-mail-for-updates/#findComment-725891 Share on other sites More sharing options...
stormx Posted December 30, 2008 Share Posted December 30, 2008 Here is an example script for you: <?php session_start(); include 'mysqlconnect.php'; $sql_users = mysql_query("SELECT * FROM `users`") or die("<strong>Error Selecting ID from users.</strong>"); while($id = mysql_fetch_array($sql_users)) { //Get details from the Database $email = $id['useremail']; $name = $id['firstname']; $subject = "Email Subject"; //Email Body $body = "Dear $name,\n Candy\n \n Regards,\n Example"; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion() ."\r\n" . ''; mail($email, $subject, $body, $headers); mail($email, $subject, $body, $headers); echo 'Email sent to '.$email.'<br />Email sent to '.$emaill.'<br />'; } echo "Sent!"; ?> It is only good for cron. Quote Link to comment https://forums.phpfreaks.com/topic/138820-auto-mail-for-updates/#findComment-725898 Share on other sites More sharing options...
champoi Posted December 30, 2008 Author Share Posted December 30, 2008 If you also have a low number of visitors, that causes issues as well (besides the extra overhead). See if your webhost (I use dreamhost, they can do this) supports cronjobs. These are scheduled actions, such as running a php file. You could have that run daily or hourly, and make a specific file that will run the checks and email processing. I use it to do maintenance on a cache, uploads, and old items on one of my sites. There are more complex methods, but this is the simplest approach. i use go daddy, and it's really a pain in the ass to use their cpanel, i'll try to find it, thnx for the info Quote Link to comment https://forums.phpfreaks.com/topic/138820-auto-mail-for-updates/#findComment-726069 Share on other sites More sharing options...
champoi Posted December 30, 2008 Author Share Posted December 30, 2008 Here is an example script for you: <?php session_start(); include 'mysqlconnect.php'; $sql_users = mysql_query("SELECT * FROM `users`") or die("<strong>Error Selecting ID from users.</strong>"); while($id = mysql_fetch_array($sql_users)) { //Get details from the Database $email = $id['useremail']; $name = $id['firstname']; $subject = "Email Subject"; //Email Body $body = "Dear $name,\n Candy\n \n Regards,\n Example"; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion() ."\r\n" . ''; mail($email, $subject, $body, $headers); mail($email, $subject, $body, $headers); echo 'Email sent to '.$email.'<br />Email sent to '.$emaill.'<br />'; } echo "Sent!"; ?> It is only good for cron. thnx Quote Link to comment https://forums.phpfreaks.com/topic/138820-auto-mail-for-updates/#findComment-726071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.