[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sending email Every hour

Posted on 2008-06-13
24
Medium Priority
?
1,371 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:fosiul01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 6
  • 5
  • +2
24 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 800 total points
ID: 21777034
If you can keep the command line open you can use a file sendmails.php

<?php

while(1) {
   //insert code to send mail
   // wait 30 min = 1800 seconds
   sleep(1800);
}

then just run in your command box
php sendmails.php
and it will send mails till the box is closed
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21777066
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
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21777122
>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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 29

Author Comment

by:fosiul01
ID: 21777139
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 ??
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21777155
not directly, but you can execute them via php. So
execute php with argument to you script-file
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21777180
yes, there are an option called argument
but i dont know what arguent shall i use ??
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21777214
the full path to your php-file that sends the mail
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21777222
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 ??
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21777297
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 ??
0
 
LVL 10

Assisted Solution

by:ray-solomon
ray-solomon earned 600 total points
ID: 21777499
This may work for you.

Put this in a php script called: create_task.php
<?php
shell_exec('./mybatchfile.bat');
?>

create a batch file called: mybatchfile.bat
This would run a command from the batch file to create a task that calls a script hourly.

@echo off
schtasks /create /tn "My Task" /tr "php ./doTask.php" /sc hourly


Then just call create_task.php from the web browser only once.
This will make the doTask.php script run hourly.


Instructions here:
http://technet2.microsoft.com/windowsserver/en/library/1d284efa-9d11-46c2-a8ef-87b297c68d171033.mspx?mfr=true


0
 
LVL 29

Author Comment

by:fosiul01
ID: 21777586
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
0
 
LVL 10

Expert Comment

by:ray-solomon
ID: 21782768
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.
:-)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 21786897
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

0
 
LVL 10

Expert Comment

by:ray-solomon
ID: 21786953
@Ray_Paseur, this person is using Windows server. Cron is only for Unix systems.
0
 
LVL 18

Assisted Solution

by:Matthew Kelly
Matthew Kelly earned 600 total points
ID: 21799137
We do this at my office. I don't want all these other guys are thinking. Windows task scheduler is a cron job. Follow these steps to set it up. Let me know if you have any problems.

First create a php file based on the attached code snippet. save it as www.mywebsite.com/mail.php

1. save code snippet as "mail.php"
2. edit variables in << >>
      If using a free email host and info is unknown: http://www.emailaddressmanager.com/tips/mail-settings.html
3. upload to www.mywebsite.com
4. Download http://sourceforge.net/projects/phpmailer and place class.phpmailer.php in your php includes directory
5. navigate with a web browser to www.mywebsite.com/mail.php to make sure it sends

Next in Windows go to "Start | Control Panel | Scheduled Tasks".
1. Click the Add Scheduled Task button
2. Click Next
3. Select Internet explorer from the list
4. Select Perform this task Daily (well change it later)
5. Click Next
6. Enter your username and password of the computer
7. Select open advanced properties and click Finish

In advanced properties
1. Add "www.mywebsite.com/mail.php" after "C:\PROGRA~1\INTERN~1\iexplore.exe" in the "Run" Section
2. Click on the schedule tab and click advanced
3. Check "Repeat Task" and say every 30 minutes for 24 hours.
4. Click OK
5. Click OK
6. Enter Windows user name and password again

The website should pop up and send an email every 30 minutes now.





<?php
 
require("class.phpmailer.php");
 
$mail = new PHPMailer();
 
$mail->IsSMTP(); // send via SMTP
$mail->Host     = "<<smtpserver>>:<<stmpport>>"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "<<uname>>"; // SMTP username
$mail->Password = "<<pword>>"; // SMTP password
$mail->From = "<<email address from>>";
$mail->FromName = "<<email name from>>";
$mail->AddAddress("<<email address to>>"); 
$mail->AddReplyTo("<<email address from>>","<<email name from>>");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject  =  "Subject";
$mail->Body     =  "Body text";
$mail->AltBody  =  $mail->Body;
        
if ( $mail->Send() )
{
echo "Email sent successfully";
}
else
{
echo "Email failed";
}
 
?>

Open in new window

0
 
LVL 29

Author Comment

by:fosiul01
ID: 21800683
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
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21800947
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
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21801031
omm I dont want to run php.EXE!!!!
i want to run suppose, mailtest.php ( php file)
0
 
LVL 10

Assisted Solution

by:ray-solomon
ray-solomon earned 600 total points
ID: 21801245
Okay, now I see you have a way to schedule a task in your control panel, the easy way.
All you have to do now is create a php script that will send out email.
There is sample code above that "matthewstevenkelly" provided.
Then for the "Path to executable file" box, you type the location of the php script in it.
You may need to ask your web hosting company exactly how to do that after you have created the php script.

Just tell them where the email php script is located on your website and ask what to put into that box.
They should be able to help you with that easily.

If you are required to use a batch file in the "Path to executable file" box, then create a batch file similar to this:

@echo off
php ./path/to/doTask.php

or forward this message to your web host for more clarification from them.
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21801303
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.....
0
 
LVL 10

Expert Comment

by:ray-solomon
ID: 21802880
Use this instead. You need to call the php interpreter.


@echo off
php C:\dir\dir\dir\httpdocs\mailtest.php
0
 
LVL 29

Author Comment

by:fosiul01
ID: 21803337
ommm it does not work

Can you run php file from by calling it from batch file ??
I am having doubt now
0
 
LVL 10

Expert Comment

by:ray-solomon
ID: 21807598
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



0
 
LVL 18

Assisted Solution

by:Matthew Kelly
Matthew Kelly earned 600 total points
ID: 21807818
Author, schedule the task on your desktop, not the server.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

649 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