Page 1 of 1

send email by language

Posted: Sun May 23, 2004 4:20 am
by sirTemplar
i have this php code which sends email to those celebrating their bday on a daily basis. it works pretty well.

but now i want something more. i have on my database a field called language. now i want is the email message text changes according to the language, i.e. when they have english message is sent while if spanish or italian, another message is sent. how could i do that? here is my present code. thanks.

Code: Select all

<? 

//Connector

// connection here

//Send email to user 

$time = date("l, F j");

$result_num_birthdays_today=mysql_query("select count(*) from users 
				WHERE DATE_FORMAT(bday, '%m-%d') = '" . date ('m-d') . "'") 
				or die ("Couldn't read the number of birthdays for this date."); 

$num_birthdays_today = mysql_result($result_num_birthdays_today, 0, 0);
				print("Today there are $num_birthdays_today birthdays today<br>");

$result = mysql_query ("SELECT name, surname, email, bday, year(bday) AS year from users 
				WHERE DATE_FORMAT(bday, '%m-%d') = '" . date ('m-d') . "'"); 

while ($row = mysql_fetch_assoc ($result)) 

{ 
    extract ($row); 
	$how_old = date ('Y') - $year; 
    $to = "$name $surname <$email>"; 
    $from = 'from: me <me@me.net>'; 
    $subject = 'Happy Birthday!'; 
    $message = "$time
	
	Dear $name $surname, you are $how_old today. HAPPY BIRTHDAY!
		
		
	sirTemplar"; 
     
    $mail = @mail($to, $subject, $message, $from); 
    if ($mail) {echo 'mail sent<br>';} else {echo 'mail FAIL<br>';} 
}

?>

Posted: Sun May 23, 2004 9:52 am
by kettle_drum
You can just make an array up of the different messages in each language and then use the required one:

Code: Select all

$subject = array(
      en => "Happy Birthday",
      fr => "blah aniversairy"
   );

   $message = array(
      en => "Happy Birthday blah, hope you have a good day",
      fr => "blah blah blah blah"
   );

   mail($to, $subject[$user_lang], $message[$user_lang]);

Posted: Mon May 24, 2004 5:09 am
by sirTemplar
thank you very much! that worked well! :D