Hi,
I am trying to use preg_replace to replace text with contact information in the database when sending emails to my contact list.
I have it working correct for the email body however the email headers contains an array and I cannot figure out the correct way to get the preg replace to work.
$text = {contact:first_name} {contact:last_name}.
$html = {contact:first_name} {contact:last_name}.
$headers = array(
‘From’ => ‘”‘.$email[‘sender_name’].'” <‘.$email[‘sender_email’].’>’,
‘To’ => ‘%{contact:first_name}% <%{contact:email}%>’
);
// Get the details of all the contacts for the given broadcast
$query=(“SELECT * FROM contacts WHERE c_id IN(1,2,3)”);
$resq=mysql_query($query);
while($row=mysql_fetch_array($resq)){
// replace the template tags and send the mails
$rawhtml = $html;
$rawtext = $text;
$rawhdrs = $headers;
foreach($row as $key => $value) {
$rawhtml = preg_replace(‘/\%\{contact:’.$key.’\}\%/ism’,$value,$rawhtml);
$rawtext = preg_replace(‘/\%\{contact:’.$key.’\}\%/ism’,$value,$rawtext);
$rawhdrs = preg_replace(‘/\%\{contact:’.$key.’\}\%/ism’,$value,$rawhdrs);
}
As I said both the text and the html strings contents are replaced correctly with the contacts information within the email body. However my problem is the headers array.
At the moment it is replacing the text in the headers but every email contains the the information from the last contact id. E.g contact 3.
I think I may need to do a foreach on the header array to get the values but i am not sure how that would work.
Thanks
Paul
