Jump to: navigation, search

PHP File Email Template

From w3cyberlearnings

Contents

PHP Email Template

This is a simple email template engine, and it uses text file.

File Content(email.txt)

Hi [[:friend]],
<br/><br/>
How are you [[:friend]]? Today is [[:today]], I will go to shopping mall to buy some clothes.<br/>
Do you want to go with me? There are many friend will go with us? Do you know [[:ourfriend]]?<br/>
<br/>
I am looking forward to hear from you? My number is [[:phonenumber]].<br/> 
We are going to meet at [[:place]].<br/> 
<br/>
See you,

[[:myname]] 

Example 1

<?php

$file_name = 'email.txt';

$array_email = array('[[:myname]]' => 'John',
	 '[[:friend]]' => 'Cristina',
	 '[[:today]]' => 'Sunday',
	 '[[:ourfriend]]' => 'Janny',
	 '[[:phonenumber]]' => '318-555-333three',
	 '[[:place]]' => 'Dillair Mall');
// open file for reading only

$file_content_1 = file_get_contents($file_name);
// replace file content 
$new_file_content = str_replace(array_keys($array_email), 
		  array_values($array_email), $file_content_1);

echo $new_file_content ;
?>

Output

Hi Cristina, 

How are you Cristina? Today is Sunday, I will go to shopping mall to buy some clothes.
Do you want to go with me? There are many friend will go with us? Do you know Janny?

I am looking forward to hear from you? My number is 318-555-333three.
We are going to meet at Dillair Mall.

See you, John

Related Links


  1. PHP File Linux vs. Windows
  2. PHP File Information
  3. PHP File Create
  4. PHP File Close
  5. PHP File Read
  6. PHP File Read Reverse
  1. PHP File Write
  2. PHP File Write to end or append to
  3. PHP File Write at Beginning
  4. PHP File Write at specific location
  5. PHP File Truncate
  6. PHP File Replace a specific word
  1. PHP File Replace a specific word with associative array
  2. PHP File Copy File
  3. PHP File Copy Reverse
  4. PHP File Search within file
  5. PHP File Delete File
  6. PHP File Template
  1. PHP File Email Template
  2. PHP File Template with MySQL
  3. PHP File Access with MySQL
Navigation
Web
SQL
MISC
References