Forum Moderators: coopster
I need some help.
I have a simple php mail script written and working pretty good. The message body of the email is stored in the database. Right now, the message is simple text, but I need to add into the message variables that will be different for each person, you know the typical stuff like custom first name.
So just above the the mailing code if I have a something like:
$first_name = $loop_findRecipient['first_name'];
$message = str_replace("'", "\'", $loop_findCampaign['message']);
How do I enter $first_name into the message body (that's stored in in the db) so that it works?
thank you.
put them together like this:
$message = $first_name . $message;
If you need to place the name in a specific spot in $message, you'll have to break $message into different components and then insert.
list ($part1, $part2) = explode("some_point",$message);
$message = $part1 . $first_name . $part2;
Something like that..
I think either explode [us4.php.net] or preg_replace [us4.php.net] are going to be the best options for you. If you can modify the message, as it is stored in the database, then adding 'cues' into the text would help. For example, if your stored email can be changed to something like this:
FULLNAME ADDRESS PHONE Dear FNAME, Thank you....
Then in your code you could use preg_replace for FULLNAME, ADDRESS, PHONE, FNAME, inserting the variables.
In the message that's stored in the database I have markers like %first_name% and %last_name%, then in the mail script:
$message = str_replace("%first_name%", $first_name, $message);
$message = str_replace("%last_name%", $last_name, $message);
$msg = "". $message."\n";
thanks again!