Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:25:12+00:00 2026-05-25T23:25:12+00:00

I have a mail function that sends out an email with content from an

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:25:12+00:00Added an answer on May 25, 2026 at 11:25 pm

    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_replace using arrays.

    I’m feeling generous, so I’ll go into some detail for you…

    example of an str_replace:

    $my_text = "my name is [NAME] and my email is [EMAIL]"
    
    $find = array('[NAME]',[EMAIL]);
    
    $and_replace = array('BOB', 'BOB@BOB.com');
    
    // then I just run the str_replace into a variable:
    
    $final_text = str_replace($find, $and_replace, $my_text);
    

    and the final text would be “my name is BOB and my email is BOB@BOB.com“

    so as you can see, str_replace searched in the variable $my_text and 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_replace with 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:

    $find = array('$name','$owner_name');//<< As some of the other guys said, you should use something like [NAME] instead of $name....
    
    $and_replace = array("$name", "$owner"); //<<<**NOTE: IF REPLACING WITH OTHER VARIABLES, USE DOUBLE QUOTES**
    
    
    $final_text = str_replace($find, $and_replace, $pro_msg);
    

    So it went into $pro_msg (which contains a string from my sql db) and searched for $name and $owner_name and then replaced it with the appropriate…

    ready for mailing…

    hope that helped someone out there…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP application that sends email using the pear Mail function. Unfortunately
I have a function that sends email using asp.net built in mail framework. I've
I have the following code that sends a message using the mail() function. Everything
I have a simple PHP script that sends a message to a specified email
i have used a mail function. after inserting every record simultaneously from multiple PC.
I've just found out that a spammer is sending email from our domain name,
I have a php script that sends an email. It currently uses the php
right now, we have a single server with a cronjob tab that sends out
I have a problem sending email from a linux machine. The application sends several
I'm trying to implement an ActionMailer function that will send out a newsletter to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.