Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hey, So I've been trying to execute the mail php function and wp_mail function in a PHP function in wordpress.

The php Function is called by a cron hook... The problem is, it doesn't execute the mail or wp_mail function at all... I even threw it inside another function which I know works perfectly, and again, the cron doesn't execute the mail command. It works outside the function and it works if I call the function manually (myfunction();) but when cron calls it, it doesnt work.

any light? wp 2.9

share|improve this question

2 Answers 2

I'd say the first thing to check is whether or not the cron is actually running properly. Whenever I have issues like this, it's usually with the cron run itself, not with the code it's calling.

Remove all of the code inside your hooked function and replace it with a single line that sets an option--something named "my_cron_last_ran" or whatever--and set the option's value to the current time. If the option doesn't appear in your wp_options table, the cron hasn't run properly.

The other troubleshooting thing I'd try is to remove everything but the mail stuff from your hooked function. If it runs and sends mail, then the issue could be that code BEFORE your mail stuff is erroring out and causing the whole thing to fail.

share|improve this answer

Based on what you wrote, wp_mail works but cron doesn't. So that's where you start troubleshooting: Find out why your function isn't triggering via cron.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.