Solved

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

Posted on 2009-07-13
6
262 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
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 400 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 400 total points
Comment Utility
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
Comment Utility
run a php code using linux command in background...
use sleep function for that...

regards
0
 

Author Closing Comment

by:phatsion
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now