send email by language

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

send email by language

Post 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>';} 
}

?>
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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]);
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

Post by sirTemplar »

thank you very much! that worked well! :D
Post Reply