user3230561
user3230561

Reputation: 445

Email formats sent using wp_mail

I want to send formatted email in the form of a html table. I am using wp_mail to send the email.

I would like to know how does formatting work? Right now I am not making any changes to the content type. If the email editor is not using html support and only plain text then what will be the impact of email sent with tags. I would want the email message to be formatted correctly in both the cases.

Upvotes: 0

Views: 1267

Answers (3)

Omid Ahmadyani
Omid Ahmadyani

Reputation: 1450

you can add template email such as here:

1.include your template

include_once(get_template_directory().'/emails/demo.php');

2.add function to file template

function email_template($id){

....
return $body;
}

*id is your varible input to your template email you can put any thing.

3.put output of your email_template() in email

$body= email_template($varibles);
wp_mail('[email protected]','subject',$body);

horra you send your template email without any plugins and external codes!

S F My English!

Upvotes: 0

Manesh Timilsina
Manesh Timilsina

Reputation: 719

You can add filter before wp_mail function and remove it after that.

add_filter( 'wp_mail_content_type', 'set_html_content_type' );
@wp_mail( 'email', 'subject', 'message');
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

You need to add following function which have been called in filters used in above code.

function set_html_content_type() {
    return 'text/html';
}

For more information on this filter, see the codex: http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_content_type

Upvotes: 1

Dinesh
Dinesh

Reputation: 4110

you can use add_filter() in wordpress for html formatting.

Like this:

add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));

wp_mail( $to, $subject, $message, $headers );

may this help you...

Upvotes: 0

Related Questions