InMotion Hosting Support Center

I'm trying to get a Cron script to work

Category: How To

jmac
Asked:
2015-07-21 2:59 am EST

Hits: 517
I have removed any sensitive information.
I believe that the problem concerns:
include('Mail.php');
include('Mail/mime.php');
What am I doing wrong with the following script?


<?
// Inspired by tutorials: http://www.phpfreaks.com/tutorials/130/6.php
// http://www.vbulletin.com/forum/archive/index.php/t-113143.html
// http://hudzilla.org

// Create the mysql backup file
// edit this section
$dbhost = "localhost"; // usually localhost
$dbuser = "usern";
$dbpass = "password";
$dbname = "dbname";
$sendto = "Webmaster <info@example.com>";
$sendfrom = "Automated Backup <info@example.com>";
$sendsubject = "Daily Mysql Backup";
$bodyofemail = "Here is the daily backup.";
// don't need to edit below this section

$backupfile = $dbname . date("Y-m-d") . '.sql';
system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile");

// Mail the file

include('Mail.php');
include('Mail/mime.php');

$message = new Mail_mime();
$text = "$bodyofemail";
$message->setTXTBody($text);
$message->AddAttachment($backupfile);
$body = $message->get();
$extraheaders = array("From"=>"$sendfrom", "Subject"=>"$sendsubject");
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send("$sendto", $headers, $body);

// Delete the file from your server
unlink($backupfile);
?>


Thank you
Jim MacLeod

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

TJEdens
Staff
10,077 Points
2015-07-22 12:56 am EST
Hello Jim,

I do not see anything directly wrong with the script. We have a PHP mail script article that you may be able to use. I would suggest trying that and see if it resolves your problem.

Best Regards,
TJ Edens

You must login before you can post a comment about this answer.

Thank you TJ
but...
I don't see how the PHP MAIL link you sent would help me!

Using my original script....
It seems as if it cannot find ('Mail.php') or ('Mail/mime.php')
Two of the "Warnings" also state:
(include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxxx/public_html/xxxxx/cron/cron.php

If you can please explain.

When I run my script "as is" via a browser I get the following:

Warning: include(Mail.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/sxxxxx/cron/cron.php on line 26

Warning: include(Mail.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/xxxxx/cron/cron.php on line 26

Warning: include(): Failed opening 'Mail.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxxx/public_html/xxxxx/cron/cron.php on line 26

Warning: include(Mail/mime.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/xxxxx/cron/cron.php on line 27

Warning: include(Mail/mime.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/xxxxx/cron/cron.php on line 27

Warning: include(): Failed opening 'Mail/mime.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxxx/public_html/xxxxx/cron/cron.php on line 27

Fatal error: Class 'Mail_mime' not found in /home/xxxxx/public_html/xxxxx/cron/cron.php on line 30


Line 26 =

include('Mail.php');

Line 27 =

include('Mail/mime.php');

Line 30 =

$message = new Mail_mime();

I understand that you do not write scripts.....BUT!
You MUST know the correct filenames and paths to: ('Mail.php') and ('Mail/mime.php')

I even tried using the paths:

include('/usr/lib/php:/usr/local/lib/php/Mail.php');
include('/usr/lib/php:/usr/local/lib/php/Mail/mime.php');

There must be someone available that can help please.
Can you help further?

Respectfully
Jim MacLeod
jmac
40 Points
2015-07-23 12:18 am EST
Hello jmac,

Thank you for contacting us. What you are seeing is PHP errors, not cron job errors. This is why TJ believed your errors to be related to the mail script, not the cron.(His link provides a successful example of how to code a mail script).

The errors you are seeing are due to trying to run your script through a browser, but the path is above the browser's access.

Our guide on How to run a cron job, explains how to set the path to your script.

We also have a guide on How to check to see if a cron job has run. This will help determine if the cron is working or not.

Thank you,
John-Paul
John-Paul
31,035 Points
Staff
2015-07-23 3:02 pm EST
I have tried inserting a new cron several time without success and removed them.

It seems that the script cannot find the following files correctly.
Could it be that I need the correct "relative paths" to those files?
--------
include('Mail.php');
include('Mail/mime.php');
--------

Would you simply provide me the correct addresses to those files for the script?

--------
include('?/xxxxx/xxxx/Mail.php');
include('?/xxxxx/xxxx/Mail/mime.php');
--------

I think that that would solve the problem.
Do you disagree?

Respectfully
Jim MacLeod
jmac
40 Points
2015-07-24 6:35 am EST
Hello Jim,

When you run a script on the web to check it, you can't use the path methodology that you tried to use. A path like /home/someone5/folder1 will work in SSH or within the actual cron job that you list (check out How to run cron jobs or the official cPanel Cron job documentation), but it won't work through the browser. We do not provide programming support as it's outside our scope, but if you test your script with something like simple "Hello World" script, you can add it to the cron job, and then check to see if it appears. If that command works, then you will have basically verified that the cron function on the server is working correctly.

If you're looking for how to correctly write that script you're trying to run in the cron job, then you may want to try a forum like PHP Coding help.

I hope this helps to answer your question, please let us know if you require any further assistance.

Regards,
Arnel C.
Arn
41,441 Points
Staff
2015-07-24 9:43 am EST
PLEASE LET ME REPEAT MYSELF!

I have tried inserting a new cron several time without success and removed them.

I realize that you don't provide programming support.

AGAIN

Would it be to much to ask?

Would you simply provide me the correct paths/addresses to these files for the script?

--------
include('?/xxxxx/xxxx/Mail.php');
include('?/xxxxx/xxxx/Mail/mime.php');
--------
jmac
40 Points
2015-07-24 11:15 am EST
0

scott
Staff
43,761 Points
2015-07-24 12:02 pm EST
Hello Jim,

You have many domains in your account, but the one that was most recently used is the one I am assuming you are working with. If you are running the script from the root folder for the domain, the Mail folder is in that, followed by mail.php and mime.php.

To use the relative paths in the code, it would look like this:
include('Mail/mail.php');
include('Mail/mime.php');

This means it will start from where the file is, look for the Mail folder and then look for the mail.php and mime.php files.

Kindest Regards,
Scott M

You must login before you can post a comment about this answer.

Scott, thank you, but.....

None of my domains are in the root of my account.
They are ALL within public_html.
There are no Mail folders in root of any of the domains nor in the root of public_html.

The only Mail folder I could find is in the "Main Root" of my account under php:
/php/Mail

Could that be the problem?

Regards
Jim MacLeod

If a domain has to be moved back to the root.....my primary domain is presently "bradenton-food-delivery.com".
I don't plan to use renew it or use it again.

I do have Cron for this running. (5 OTHER non-associated crons are running correctly)

curl -A cron http://sarasota-bradenton-vehicle-listings.com/autobackup.php

Schedule to run a 6am everyday.

The Cron resides in the root of sarasota-bradenton-vehicle-listings.com and is named autobackup.php
jmac
40 Points
2015-07-25 3:14 am EST
Correction to my last...
6 (six) OTHER non-associated crons are running correctly
jmac
40 Points
2015-07-25 3:19 am EST
Hello Jim,

If you use the format I gave you earlier for a domain using the public_html folder as the root, you should be fine. Be sure to copy that Mail folder into the root for that domain. So if the domain you are usign is example.com and the root folder for that domain is public_html/example.com you will want to copy that Mail folder (and it's files) into the public_html/example.com folder.

Kindest Regards,
Scott M
scott
43,761 Points
Staff
2015-07-27 1:38 pm EST
Scott

Thank you
That seems to have worked

Regards
Jim
jmac
40 Points
2015-07-30 1:53 am EST
Like this Question?

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!