I have a mail function that sends out an email with content from an sql db.
The message that will be included in the email will be taken from the sql db. The message in the sql db has variables in it…..
example:
In the database:
Hey $name, $owner_name here
Everything works fine, except i cant get PHP to print out that var when it sends the email.
So the final email that goes out is:
Hey $name, $owner_name here
When it should be:
Hey BOB, Johnny here
Here’s the mail function code;
get_email_settings($db_host, $db_user, $db_pswrd, $db_name, $email, $pro_msg,$pro_subject);
mail($email_usr, $pro_subject, $pro_msg, "From: $my_email");
Now I’ve also tried: (NOTE: the double quotes)
mail($email_usr, "$pro_subject", "$pro_msg", "From: $my_email");
And I’ve also tried inserting the content into the DB with double quotes so: "Hey $name, $owner_name here" instead of Hey $name, $owner_name here…
Both do the same thing…
Any Ideas?
OK, I got it working.
For anyone else who has this issue, and wants a slightly more clearer answer, here it is:
All I done was a multiple
str_replaceusing arrays.I’m feeling generous, so I’ll go into some detail for you…
example of an
str_replace:and the final text would be “my name is BOB and my email is BOB@BOB.com“
so as you can see,
str_replacesearched in the variable$my_textand looked for [NAME] and [EMAIL]. It then replaced them with either BOB (for [NAME]) and BOB@BOB.com (for [EMAIL]). BUT when you do this, make sure the replace variable ($and_replace) has the data in the right order… for example, if i did this$and_replace = array('BOB@BOB.com','BOB');instead of this$and_replace = array('BOB', 'BOB@BOB.com');then it would replace [NAME] with BOB@BOB.com and [EMAIL] with BOB. So make sure you get the right order….So in my case, using
str_replacewith a string coming from an SQL db:It’s piratically identical to the example i wrote above, instead you just don’t create the string variable ($my_text). You just use the variable that has the db content in it (in my case
$pro_msg)so:
So it went into
$pro_msg(which contains a string from my sql db) and searched for$nameand$owner_nameand then replaced it with the appropriate…ready for mailing…
hope that helped someone out there…