Link to home
Start Free TrialLog in
Avatar of fosiul01
fosiul01Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Sending email Every hour

HI will any one help to write a php script which will sent email to a specifiq email address Every 30 min.

I know how to sent email but i dont know how i will do automated Every hour by using timer or something like this

Here : I want by php, No contrab as i dont have Administritive right of my server.

Thanks for the help
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fosiul01

ASKER

ommmm i didnot understand what you said,
what is command line ??

the purpose of this question is : we have having problme of my Exchnage server, Some time its giving trouble of receiving email. thats why, i want from my Webhost to send email my exchange sever every 30 min to check, if it receive email or not.

so i have my own web site suppose : www.mydomain.com ( which is hosted in web hosting companies web server)
i want to sent email from there
>what is command line ??
cmd.exe

not possible via a webserver. Either you need a server where you can trigger a script on the remoteserver to send every 30 minutes. Running the script via webserver is not possible as the webserver kills the process after a certain time. You need a server which is capable of a task planer or cron-Server
ommm yes , Think so, but in my control panel , there is an options called, shcedule taks where i can run executable file like crontab

but my question is, can i run php file as executable file ??
not directly, but you can execute them via php. So
execute php with argument to you script-file
yes, there are an option called argument
but i dont know what arguent shall i use ??
the full path to your php-file that sends the mail
there are 2 fields :

Executable file path : httdoc/cronemail.php

Argument :  ??

i worte file path in Executable file path
 Argument is empty

Still it didnot sent me any email

do i need to write anythign in Argument ??
I emaild to hosting company , they reply me this
You can not schedule any script using schedual task as scripts like .php / .asp requires IIS execution. You can do this through btach (.bat) file only. All you need to do is, create a .bat file and put all instructions in it. Regarding questions how to create a .bat file you must google it.

do you have any solution of this ??
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi ray
but what command shall i write in batch file to send email ??

and also, the hosting company guy saying, i cant run php script from Schedule task
i will have to write bath file with .bat extenstion
You don't write anything in the batch file for sending mail.
The batch file will simply contain a command that initiates another program that will schedule a program to be executed.

In doTask.php is where the php code for sending the email goes.
Read and learn.
http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php
http://www.google.com/search?hl=en&q=sending+email+php

In the batch file, you would have a command like this:
@echo off
schtasks /create /tn "Send out emails" /tr "php ./doTask.php" /sc minute /mo 30

That command basically means that it will create a new schedule that will run doTask.php every 30 minutes.
So, doTask.php will send emails every 30 minutes.

or, if you want the emails sent out every hour instead, use this command in the batch file:
@echo off
schtasks /create /tn "Send out emails" /tr "php ./doTask.php" /sc hourly


To delete the task, use this command:
@echo off
schtasks /delete /tn "Send out emails" /f



>>and also, the hosting company guy saying, i cant run php script from Schedule task
i will have to write bath file with .bat extenstion

That is why I previously stated to use php code like this to execute the batch file.
Put this in a php script called: create_task.php
<?php
shell_exec('./mybatchfile.bat');
?>


This is all a simple 3 step process. It just seems complicated because it is new to you.
Take your time and learn carefully.
:-)
fosiul01: Learn about "cron jobs" and it will make the scheduling easy.  Learn about the PHP mail() command and you will be set up with all the background knowledge you need.

http://en.wikipedia.org/wiki/Cron
http://us3.php.net/manual/en/function.mail.php

Good luck, ~Ray

@Ray_Paseur, this person is using Windows server. Cron is only for Unix systems.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good morning
Sorry from last 3 days i was not well thats why didnot able to reply
thanks for every one's respond
But still there is problem :

matthewstevenkelly : Your solutions would not work as i will not be able to create Schedule task as i dont have any administrative acccess over my web server( as i said, its shared hosting)

Hi ray-solomon,

Your idea should work, but there is a problem, the code you have sent for batch file : it actually trying to create schedule , which its impossible for me.
check the picture please, here, from Control panel i would be able to create Scheduling task

I think, the solution is, from batch file, i need to run the php file thats all

do you know, how i will run php file from batch file ??

Scheduler.GIF
PAth to execute file should be something like /usr/bin/php
Andas argument use full path to your php-file /home/pages/www.xyz/file/run.php
omm I dont want to run php.EXE!!!!
i want to run suppose, mailtest.php ( php file)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok what i did so far , let me tell you .
let me expalin :

i created a php script which is mailtest.php   ( which will send email)

and from bath file i used this to run the php file :
@echo off
START /MAX C:\dir\dir\dir\httpdocs\mailtest.php

now i  have created the schedule task to run the batch file

omm but it does not run mailtest.php

problem.....
Use this instead. You need to call the php interpreter.


@echo off
php C:\dir\dir\dir\httpdocs\mailtest.php
ommm it does not work

Can you run php file from by calling it from batch file ??
I am having doubt now
Obviously it is not setup as an environmental variable.

Ask your host for the full path to the php interpreter.
or ask them how to simply execute a php script from a batch file.

It would be something like this:
@echo off
C:\Program Files\PHP\php.exe C:\dir\dir\dir\httpdocs\mailtest.php



SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial