0

Hi friends I have created newsletter system. In which I want to send person name like typing Hello %username% in html form, which will be coming from database $username. So when the person get email He will have "Hello Falana".

Thanks

3 Answers 3

3

The concept is called mail merge. You will have to write a script to do that. This is how it will work: (its for you to get a rough idea, NOT a code)

$emailBody = " Hello %USERNAME%"; 


foreach($members as $member_information){
$emailBody = str_replace('%USERNAME%',$member_information['user_name'],$emailBody);

sendMail($member_information['email_address'],$emailBody);
} 
Sign up to request clarification or add additional context in comments.

1 Comment

;) hehe .. wanted to be more specific so I was trying to write a pseudo-type code, which didn't work
1

you can go with str_replace:

$html = "Hello, %username% .....";
$html = str_replace("%username%", $username, $html);

where $username contains the real name from the db.

1 Comment

Think that should be: str_replace("%username%" (otherwise everyone's username will end in %)
0

If you have multiple find/replaces look into the preg_replace() function.

$data = 'Find1 / Find2 / Find3';

$patterns[0] = '/Find1/';
$patterns[1] = '/Find2/';
$patterns[2] = '/Find3/';

$replacements[0] = 'Replace1';
$replacements[1] = 'Replace2';
$replacements[2] = 'Replace3';

$data = preg_replace($patterns, $replacements, $data);

1 Comment

str_replace($patterns, $replacements, $data); will work the same way (without the delimiters in $patterns, of course).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.