silent_coder14
silent_coder14

Reputation: 583

Correct syntax for PHP Cron Job in CPanel

I wanted to send a simple email in php that can be triggered by CRON jobs in CPanel..

php /home/username/public_html/test/email.php

I am using the above script to run the script and send an email to me but no luck...

<?php
$to = "[email protected]";
$subject = "I'm CRON from CPanel";
$message = "Just wanna say that your cron is working";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

I am using the above PHP script as well..

Why is it that it is not sending email?

Upvotes: 1

Views: 2385

Answers (2)

darkAsPitch
darkAsPitch

Reputation: 1875

This is what works for me:

php /home/username/folder/script.php >/dev/null 2>&1

As for your question "Why is it that it is not sending email?"

Considering it is being sent to [email protected] you would have no idea if it was or if it was not being sent anyways.

Upvotes: 1

Rohit13
Rohit13

Reputation: 299

Try this :- php -f /home/username/public_html/test/email.php Also check your Home Directory "/home/username" in cPanel

Upvotes: 1

Related Questions