Jump to content

Placing Users First name in the e-mail message!


demeritrious
Go to solution Solved by requinix,

Recommended Posts

I believe the solution the my problem should be simple I feel that it's staring me right in the face. I have a Cron Job that sends an email message to users who's bill "due date" falls on the current date. I want to make the email more personalized and say:

 

Dear John Doe:

 

You have the following bills due today:

 

Rent

Cable

Internet

 

Please login to pay your bills

 

Thanks,.

 

Here's my following PHP code

<?php
header("Content-type: text/plain");
 
// OPEN DATA BASE
define("HOSTNAME","localhost");
define("USERNAME","");
define("PASSWORD","");
define("DATABASE","");
 
mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die("Connetion to database failed!");
mysql_select_db(DATABASE); 
 
joinDateFilter();
 
// BILL QUERY
function joinDateFilter(){
     $query = mysql_query("SELECT bills.billname, bills.duedate, bills.firstname, bills.email, bills.paid FROM bills JOIN users ON bills.userid=users.userid WHERE DATE(bills.duedate) = CURDATE() AND bills.PAID != 'YES'");
     $mail_to = "";
     while ($row = mysql_fetch_array($query)){
      echo $row['firstname']." - ".$row['email']."\n";
  $mail_to = $row['email'].", ";
     }
     if (!empty($mail_to)){
      sendEmail($mail_to);
     }
}
 
// SEND EMAIL
function sendEmail($mail_to) {
$from    = "MyEmail@myemail.com";
$message = "Dear " . $row['firstname'].", <br><br>"
 
."You have the following bills due today.<br><br>"
.$row['billname']. "<br><br>"
."Please login to pay your bills";
 
$headers = 'From: '.$from."\r\n" .
'Reply-To:'.$_POST['email']."\r\n" .
"Content-Type: text/html; charset=iso-8859-1\n".
'X-Mailer: PHP/' . phpversion();
mail($mail_to, "Today is your due date", $message, $headers);
}
?>
Edited by demeritrious
Link to comment
Share on other sites

  • Solution

I'm not sure what you're describing but your code should look something like

sendEmail($mail_to, $row['firstname'], $row['billname']);
function sendEmail($mail_to, $firstname, $billname) {
$message = "Dear " . $firstname.", <br><br>"
 
."You have the following bills due today.<br><br>"
.$billname. "<br><br>"
."Please login to pay your bills";
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.