Solved

Is it possible to send automatic ( hourly or more ) emails with a php script??

Posted on 2009-07-13
6
269 Views
Last Modified: 2013-12-25
Hi,
I am fairly new to php, but have a little experiance with basic includes, and email forms etc..

is it possible to send an email to 2 or 3 addresses, every 60 mins ( or less time? )

I am running a local charity music consert, and we have set up a myspace and facebook accounts -
using a site called ping.fm - you can update you status on these other sites by sending an email to - for example: myID1234@ping.fm

So my plan is in the days leading up to the event, to regularly update. if this could be done using a php ( or other ) script, this would be brilliant.

Idealy, i would have 2 or 3 different messages, so it would cycle through them.
But it wouldnt be the end of the world if it was the same everytime - if that makes it alot simpler.

Any help, or pointers would be much apreciated.

Cheers.
Sean.
0
Comment
Question by:phatsion
6 Comments
 
LVL 1

Assisted Solution

by:unluckynelson
unluckynelson earned 100 total points
ID: 24840333
Some ISP's allow cron jobs on their website hostings... Log on to your website's control panel and see if you have something like that.

Otherwise start a windows schedule that simply opens your php script every two hours and leave your pc on...
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 400 total points
ID: 24840933
Almost every hosting company offers some kind of "cron" capability.  You might also find that Twitter is useful for this purpose, and you can set up automated posts to Twitter.  If you decide you want that, let me know and I will post my Twitter class for  you.

best regards, ~Ray
0
 

Author Comment

by:phatsion
ID: 24841945
Hi,,,, back again...

so after spending a while searching around for some one who hostes these for free - i found a couple.
still waiting for the best on ( i think ) to come to file.

In the mean time, i found a site called http://cronless.com

where it runs cron jobs for you at ny address.

i have been trying this, and it doesnt seem to work.

all i have done, is poped the attached code into a file, and called it email.php
uploaded it, and then set cronless to run it.

i also noticed that when i visit it in a browser, it doesnt work.

Am i missing something??

I should probably mention that the host where the file is held automaticly adds a div to the page..
should this matter??
-- also, should i be able to see the php code when i select view page source.
the page is here: http://sdr1.emenace.com/email.php

cheers
Sean.
<?
    $email = "me@hotmail.com";
    $subject = "Sent from a crontab";
    $message = "This is a message sent from a crontab";
 
    mail($email, $subject, $message);
?>

Open in new window

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 110

Accepted Solution

by:
Ray Paseur earned 400 total points
ID: 24842166
Here is what I would recommend.  Get a REAL hosting service, the kind you pay for.  They are very inexpensive, less than a cup of coffee per day.  I use and recommend ChiHost.com.  Tell Nick Gilbert I sent you ;-)

They have a complete control panel, and they have competent telephone and email tech support to help you set up your cron job.  

Nothing against the free services, but you often get what you pay for.  I am, therefore, not surprised that it's not working out and that there is nobody to go to for help.

You might want to try changing the code as shown below.  Obviously you need to correct the email address.  You might also want to echo the results of the mail command.  I would not be surprised if the free host disables the mail command - too easy to become an open relay for spam if you do not.
<?php // USE THE FULL HEADER, NOT THE SHORT OPEN TAG
    $email = "me@hotmail.com";
    $subject = "Sent from a crontab";
    $message = "This is a message sent from a crontab";
 
    if (!mail($email, $subject, $message)) die('MAIL FAILED');
?>

Open in new window

0
 
LVL 7

Expert Comment

by:ajkhalifa
ID: 24842270
run a php code using linux command in background...
use sleep function for that...

regards
0
 

Author Closing Comment

by:phatsion
ID: 31602854
Thanks for your help on this.
Using the cron jobs seems to work fine.
I mannaged to get free hosing, with x10hosing.com
- allthough they offer cron support, i couldnt get it to work with them.

setcronjob.com is a site that you can set cron jobs on, and they run scripts hosted with other hosts.
This was probably a long way around it, but it works, and was simple to setup.

Cheers.
S.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
show child records separated by commas 12 34
How to use session variables in php? 22 42
bulk create of subfolders in multiple parent folders 9 50
Put POST values into cookies. 14 29
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question