Hi All,
Is there any way to send email in php without user interaction.The scenario is some thing like this.. I want to send email's to persons based on his/her birthday.I need your help. Please help me to solve this...

Thanks :)

Dani AI

Generated

As suggested, the usual solution is a scheduled task that runs a PHP script daily (cron on Linux, Task Scheduler on Windows). A simple, reliable workflow: keep birthdays and a last_birthday_email_sent timestamp in the database; run a CLI PHP script once a day that selects today’s birthdays, sends mail via an SMTP-capable library, and updates last_birthday_email_sent to avoid duplicates.

Important implementation points:

  • Use an SMTP library (for example, PHPMailer) rather than relying on mail() for better deliverability and authentication (PHPMailer, PHP mail() docs: php.net).

  • Query for birthdays using month/day and check last_birthday_email_sent so each person gets one mail per year. Example SQL:

    SELECT id, email
    FROM users
    WHERE MONTH(birthdate) = MONTH(CURDATE())
      AND DAY(birthdate) = DAY(CURDATE())
      AND (last_birthday_email_sent IS NULL OR YEAR(last_birthday_email_sent) < YEAR(CURDATE()));
  • Send personalized multipart (text+HTML) mail, log successes/failures, and update last_birthday_email_sent only after successful delivery.

Schedule example (Linux cron): run the script at 09:00 daily.

0 9 * * * /usr/bin/php -f /var/www/scripts/send_birthday_emails.php >> /var/log/birthday_email.log 2>&1

Notes and troubleshooting:

  • Test the script manually before scheduling; check cron logs (/var/log/syslog or /var/log/cron) and PHP error logs if jobs don’t run.
  • Ensure the correct PHP binary path and file permissions.
  • Mind time zones (set PHP timezone or run cron in the intended zone).
  • For shared hosting without cron access, use the host control panel or a web cron service.
  • Deliverability: use authenticated SMTP, set SPF/DKIM, respect unsubscribe rules and privacy laws to avoid spam issues.

For cron syntax and options see the crontab manual (crontab(5)).

Recommended Answers

All 2 Replies

you need to use a cron job. search google for it and I think you'll find your answer.

Thanks..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.