Solved

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

Posted on 2009-07-13
6
263 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 108

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 108

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

863 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

20 Experts available now in Live!

Get 1:1 Help Now