You should use str_replace, which accepts arrays as arguments:
$content = "Email: {{email}}\nFirst Name: {{first_name}}";
$body = str_replace(
['{{email}}', '{{first_name}}'],
['[email protected]', 'Mickey Mouse'],
$content
);
Be careful about using $
in your placeholders. Since it’s widely used in PHP, it’s not safe. It was the reason I’ve used mustache-like syntax in my example.
Related Posts:
- How to add elements to an empty array in PHP?
- WordPress refuses to send mail, “…your host may have disabled the mail() function”
- Where to get information about array fields in $_REQUEST?
- WordPress “phpmailer_init” not working for me
- Pass a PHP variable to another file
- How do I override the Message-ID header of wp_mail function?
- How to store the_title() into a variable to reutrn the value, not just echo it
- Variables declared in header not available in other includes
- How do I make my function add variables/values to the $post object?
- WordPress new user / forgot password emails are broken
- wp_mail function timing out
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Why is my get_post_meta always empty
- where to include a php file
- Should I use wp_mail or PHP’s mail? [duplicate]
- How do I know what variables are passed in a filter/action and what their meaning is?
- Mail not sent when I set HTML headers
- Error when requesting password reset email – wp authentication
- Processing a subscription form with POST method?
- When would you use $_post instead of $post?
- Different Webhost and using Google Mail server: Is there a better way than SMTP?
- wp_mail not sending
- Validate emails in array using foreach
- Locating Global Variables
- Pass PHP variable to JavaScript without inline JS
- Count the number of times the search form template gets included on a page
- Putting PHP variables into javascript [duplicate]
- Variable global scope [closed]
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Using a variable in is_page(array())
- Redirect to another page after submission using wp_mail
- Static variable and add_rewrite_rule?
- How to put a variable in a instance in the widget
- Call global variable array() in woocommerce child/template
- get_term_link() returns correct – But illogical error-messages disturb
- How can I Add a variable PHP in the Menu Nav
- Pass variable from one function to another
- Get value from shortcode to do something
- PHP 8, AJAX mail form to function.php doesn’t work
- PHP, Creating a dynamic variable
- How to modify a global variable in a function and use it on another function?
- How to retrieve the sender email with wp_mail()?
- wp_mail file attachment not being placed in upload folder?
- Website needs to be opened for wp_mail to work
- Variable not staying set
- Notify users only on post publish
- Sending a custom form data in email through WP Mail Function
- WordPress function and string as variable?
- Create a WordPress shortcode using PHP [duplicate]
- How to pass a PHP $_GET variable and fetch/output it?
- Creating WordPress Shortcode with Variable
- How to put a form with php code into a variable or shortcode?
- Apply class to every third list item? [duplicate]
- persist a variable set in header.php all the way down to footer.php
- Get access to variable from previous pageview, excluding ajax-calls
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Insert page content into another page with a changed variable
- How to access or parse key/values that have “string”
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- javascript variable to wordpress php variable
- Pass return-path additional parameter in wp_mail
- Send notification email to admin for every new post published
- Different SMTP based on domain
- How to reference PHP in Javascript
- Store and Change Session variable – PHP SESSION VARIABLE
- Overide Variable in Child Theme
- echo var into wp_query
- how can I include some custom variable from functions.php?
- Dynamically adding filters
- PHP variables in a post?
- WordPress is removing query variables like page, p from the URL of a custom static page
- Get page permalink in contact form
- How to send a php var to jQuery Ajax call with two different file
- If I define a variable in header.php, how do I make it available to templates?
- Shortcode not passing variable to included file
- ACF allow zero as a value
- Can’t get options with $data[‘variable’]
- PHP Use Declared array Variable inside already Declared Array
- How to show value from ACF plugin field in e-mail?
- Import and use a variable in additional settings of Contact Form 7 [closed]
- Use ajax response in PHP function
- WP query with variables gives no result for specific user
- wp_mail vs mail functions and header arrays
- How can one use variables in a template or template part without polluting the global scope?
- Word press – JSPDF – Sending PDF as attachment from wp_mail – Special characters
- How to make my scroll bar show under condition
- PHP Warning: Attempt to read property “id” on null
- wp_mail – send emails after 24 hours from users registration
- Send emails to individual subscribers when CPT post is deleted (trashed)
- How to access admin menu labels and links on front-end?
- Send email with a PDF embedded
- Edit password change email text or disable it
- Send summary email from a form with wp_mail
- How to get default variation ID (woocommerce)
- Get check box values inside array for use in posting form data
- How can I save the HTML output of a WP_Query function as a variable?
- Send registration email to all admins