Jump to content

Recommended Posts

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,

Link to comment
https://forums.phpfreaks.com/topic/138820-auto-mail-for-updates/
Share on other sites

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.

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.

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  :D

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 :D

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.