This topic is locked

Script to send birthday email

2/10/2024 3:35:18 PM
PHPRunner General questions
M
MarkDonners author

I would like to run a birthday.php script using Cron and I need some help with the script
I have a table called Members and one field is called "Date of birth".
So I need some sort of query that selects all birthday celebrants for today...and send them an email using runner_mail

I know its only a few lines of code but can't get it to work in the phprunner enviroment.

This is what i got so far ( but not using the phorunner enviroment, as in addressing the database seperate in this example)
( fields in members table: 'Date of birth', Name, email

I need some help converting this to a script in which runner_mail and the database connection is done using phprunner

<?php

$date = date("m-d");//here my date format in my DB is 12/29, basically it grabs the current date
$today=date("Y-m-d");
$link = mysqli_connect('localhost','root','','portal');

if($link)
{
$grabBday = "SELECT * FROM members WHERE `Date of birth` LIKE '%-".$date."'";
//here it will take the name of the person whose bday is on a particular date
$result = mysqli_query($link,$grabBday);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["Name"]."'s Birthday Is Today ".$row["Date of birth"]." An email will be sent to ".$row["email"].".
";
// mail($row["email"], 'HAPPY BIRTHDAY', 'MESSAGE');
//runner_mail(array('to' => $row["email"], 'subject' => "test onderwerp", 'body' => "Dit is een mooi bericht"));
}
} else {
echo "0 results";
}

mysqli_close($link);

} ?>
C
cristi 2/11/2024

First of all the manual:

If you need to access PHPRunner session variables or any PHPRunner API from your custom file, add the following as the first line in your PHP file:
include("include/dbcommon.php");
This code snippet assumes that your external PHP file is located in the main PHPRunner folder.

After that in your 'while' loop:

$email=$row["email"];
$from="email@email.com";
$msg="your message";
$subject="Happy Birthday";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

Check the manual for more guidance: https://xlinesoft.com/phprunner/docs/send_simple_email.htm