Support » Developing with WordPress » Send e-mail template with wp-mail()

  • Hello !
    On my function.php i make my own function to send an email to customer. But, i whant to send a big email to customer (the email code ~ 3000 lines) because i have a lot of CSS and content..

    So, i dont want to put all in my function.php, i want to know if its possible to say “$message = this_template.php” and in this template i have all my code..

    Thanks you.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s possible, but not like that. Use the PHP include or require statements to reference your message content. The result is the same as though you copy/pasted the file contents (except the initial <?php ) in replacement of the require statement. Thus your required file should be valid PHP syntax in itself, something like this:

    <?php
    $message = 'Dear valued customer,<br>...blah blah...';

    The difference between include and require is only an issue when the file cannot be opened by the server. Require causes a fatal error, include merely throws a warning.

    I should warn you (apologies if it’s nothing new to you) that many email clients will ignore a lot of CSS styling, especially positioning rules. Font styling when the font is native to the local machine will generally work correctly. If the mail goes to a specific customer and you know what email client they use, you can do specific testing to be sure the message appears the way you want. Otherwise, test on as many platforms as you can and try to keep your CSS to the very basic.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.