How to bypass templating in e-newsletter to create new template?

How may I bypass the whole "template + content builder" in order to use an automatically generated template, from custom content ?

I was thinking that I could update the 'enewsletter_newsletters' table because that is what the builder does, doesn't it ?

Especially, I'm able to develop any template required and to pull any content from the DB.
All I need is information about where to store stuff in the DB so that I may just press "send"
If there are any manual steps left, such as chosing an e-mail title or selecting a mailing-list, that's fine, but the main task is to save time building the e-mail, since I have all I need to generate it with a custom function.

  • Ivan

    Hi Greg !

    First of all, you can make your own template and then you can use it whatever you want. (More info here - https://premium.wpmudev.org/project/e-newsletter/ -> Usage section -> Using Custom Themes )
    Also, if you are familiar with WP filters ( https://developer.wordpress.org/reference/functions/add_filter/ ) - you can make MU plugin ( https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/ ) and use email_newsletter_make_email_body filter which applies after generation entire email content and which has two params: the first one is $contents ( you can replace or partially change it ) and the second one is $newsletter_id ( for creation different templates for different newsletters )

    Best,
    Ivan.

  • Greg

    Dear Ivan,

    Thank you very much for your help.
    I've managed to get most of what I wanted out of the plug-in.

    However, I do have a few questions left :
    1) How may I test my e-mail deliverability ?
    Because I guess that switching from a paying service (MailChimp) to a self hosted tool (WPMU's e-newsletter) coupled to a free mail STMP service (ZOHO) would certainly end up decreasing my deliverability, wouldn't it ?

    2) How can I make sure that I send both HTML and TXT e-mails ?
    And what should I do in my custom template to make it txt compatible ?

    3) I have set-up SPF and DKIM, following a guide. But I pretty much have no idea what I did... Is there anything related to that to include in the custom template and/or settings ?

    Thank you for your help !

  • Greg

    Sorry for the double message. On top of that, I would have a more questions :

    4) Could you please tell me what is the "bounce_email" field for, in the database ?

    5) There seems to be a conflict in the CSS, between the newsletter in WP and what I receive in my email.
    For instance :
    This is what the newsletter looks like within WP :
    https://s18.postimg.org/nq3ebacnd/screenshot.jpg

    This is what it looks like in Thunderbird :
    https://s18.postimg.org/49na1xtw9/screenshot.jpg

  • Ivan

    Hi Greg !

    How may I test my e-mail deliverability?

    The best of my knowledge, SMTP service provides information about quotas.
    Furthermore, you can use the Test Connection functionality for checking does SMTP work or not -

    And also, you can see the CRON Email Sending Settings a little bit below there and set relevant quotas which you'll get for SMTP.

    2) How can I make sure that I send both HTML and TXT e-mails?

    If you are talking about some HTML/text labels in the plugin - it means that it supports both formats there but it sends only one email, independently what do you input there.

    And what should I do in my custom template to make it txt compatible?

    It seems you should test it on some E-mail servers which don't support HTML-format or maybe some Email services provide special features for it ( like Show Original option in Gmail ).

    3) Is there anything related to that to include in the custom template and/or settings?

    No, you don't should worry about it in the templates or the settings.

    4) Could you please tell me what is the "bounce_email" field for, in the database?

    It's a Bounce email which you set when you create a new Newsletter in the Settings tab. More about Bounce emails here - http://searchexchange.techtarget.com/definition/bounce-e-mail

    5) There seems to be a conflict in the CSS

    Actually, it's not a conflict, because there are a lot of Email services around and they display some specific HTML-tags or CSS-styles in different ways. Moreover, the best of my knowledge, some Email services add their own specific style to each Email for showing emails in the same way for different browsers and for their mobile applications and so on. But, in general, if you use standard HTML-tags and CSS-styles it should have the same look. By the way, you can use Send Preview functionality for being sure that an email has a perfect look.

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you for your help.

    1) About "testing my deliverability", I meant "how may I check if my e-mails are likely to end-up in the spam folder ?"
    1b) Thank you for your advice on testing SMTP, it works just fine now. Could you please tell me more about this Cron feature ? Does it add a cron event in WP ?

    2) Thank you, I'll check that out with a test email in Gmail and give you feedback in case there isn't any TXT version.

    3) Got it, thanks !

    4) Thank you for the link. I still do not understand how this settings impacts the overall newsletter sending process. Is it the adresse to which the bounces are sent ? Should I use the same adresse I used in the POP3 settings ? Is its purpose to keep a list clean ?

    5) I'm surprised by this points. I thought I was using standards CSS and HTML pieces.
    Using your plug-in, I have the CSS file of the template, which is standard. There's also the template.html file, that is also standard.
    Shouldn't that be enough ? Should I use only CSS ?

    Thank you for your help and time.
    Greg.

  • Ivan

    Hi Greg !

    1a) The plugin doesn't provide this information. Maybe this article will be helpful for you or maybe you can find a better one - https://help.activecampaign.com/hc/en-us/articles/206427664-Why-is-my-email-going-to-the-spam-folder-How-to-improve-email-deliverability
    1b) Yeah, it creates a WP cron which runs every 2 mins and takes into account the settings about SMTP quotas. All WP crons run automatically but triggered by a visitor. It means if nobody opens your site 5 hours - none WP cron runs.

    4. Exactly, it's the address to which the bounces are sent. If you don't want to use this ability - you can leave this field empty and you'll get bounce notification to the "Email From" email.

    5. Could you do a few tests? Please, create a new Newsletter with our default template, add only text there without any HTML pieces and CSS-styles, check how it looks in Thunderbird. If it looks fine - it means your HTML or CSS break it and you should investigate what it's wrong because creating good Email Templates is a big deal. By the way, there are many services for creating good Email templates on the Internet. It still looks incorrectly - could you check it in other Email services? (for example, Gmail) If it's without any luck - please, tell us how is the template called - we'll investigate it more.

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you for your help.

    1a) Nice article, I'll keep that in mind, cheers.

    1b) OK, that's fair, I'll try that.
    Actually, I worked with my host to disable this WP cron system (that I personally find really bad) to use a proper cron, triggered by the server itself but still using WP hooks. (that might be a good idea for a WPMU post).

    2) I did test the plain-text version of my newsletter, using Thunderbird (https://www.campaignmonitor.com/blog/email-marketing/2007/05/testing-the-plain-text-version/)
    It looks absolutely horrible !
    How may I improve it ? Is there anything related to plain-text e-mail generation in the plug-in ?

    4) OK, I'll use my bounce address there, then. But I'm surprised that I would have to specify it for each campaign since I set it up in the settings tab. Isn't there something redundant, here?

    5) About the CSS conflict.
    Here is my process :
    a) I have a hidden page, where I have a list of all my posts with some information and links on it.
    b) I use it to call a function that generates the "content" field of the newsletter and inserts (or updates) a row in the wp_7_enewsletter_newsletters table.
    c) Then I have a link to the editing/sending page. For instance : /wp-admin/customize.php?wp_customize=on&theme=defiecologique_article&newsletter_id=1&return=admin.php%3Fpage%3Dnewsletters
    d) Once I'm on this page, at first, the newsletter CSS looks broken :
    https://s18.postimg.org/iiliya6kp/test.png
    e) After a few seconds, the newsletter is displayed nicely
    https://s18.postimg.org/kzxa5lg7d/papillons.jpg
    f) When the preview is sent, it looks like the first version (see d above)

    Now, here is a screenshot of the e-mail using the "Disco" default theme : https://s18.postimg.org/4q7429ajt/papillons.jpg
    The preview e-mail looks exactly the same way.

    So, how may we explain the fact that two versions are loaded and that it takes a few seconds from one to the other, and that the e-mail sent matches the first version and not the second one, which is the one I want ?
    Here is a link to my full custom theme : https://files.fm/u/6ejwr9xq

    Regards,
    Greg

  • Ivan

    Hi Greg !

    2) Unfortunately no, there is not something special for plain-text e-mail generation in the plugin.
    4) Some members want to specify bounce email for each campaign.
    5) I downloaded and installed your template on my test site. Then I created a new campaign with your template and I don't see issues with you described. Moreover, I sent a preview and it looks like in the plugin.

    Just to make sure no other plugin is conflicting and causing this, can you please do a plugin conflict test? To know more about plugin conflict test, you can check this guide: http://premium.wpmudev.org/manuals/using-wpmu-dev/getting-support/

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you for this help.

    2) Is there anything I may do to re-write the text-email generation ? I could code a custom function, without any problem.

    4) OK, thank you for this info.

    5) Thank you for this test.
    I did a test too, where I only have written "test" as content :
    https://s18.postimg.org/e2n2m2sah/screenshot.jpg
    The word "test" does not even appear in the preview zone.
    Could you please try a test with the following content ?

    <div id="generated_html">
    							<h1 class="center_m"><a href="https://devblog.defi-ecologique.com/chasse-au-sanglier/">La chasse au sanglier&nbsp;: histoire d’une escroquerie nationale</a></h1>
    							<div class="center_m centre"><a href="https://devblog.defi-ecologique.com/chasse-au-sanglier/"><img src="https://www.defi-ecologique.com/wp-content/uploads/chasse-au-sanglier-476x249.jpg"></a></div>
    							<p class="center_bm centre" id="quote">&laquo; Aussi longtemps que les lions n'auront pas d'historiens, les récits tourneront toujours à la gloire du chasseur ! &raquo;&nbsp;&mdash; Proverbe africain</p>
    							<p class="center_bm" id="resume">La chasse au sanglier est, en réalité, mal connue dans son fonctionnement et dans ses problématiques. Dommages agricoles, adaptation de l'espèces et autre cynégétique justifieraient l'abattage de 600 000 spécimens par an… Ah bon&nbsp;?</p>
    							<div class="cqvaa clear">
    								<h2 class="center_m">Ce que vous allez apprendre</h2>
    								<ul class="center">
    									<li><span>Pourquoi les sangliers sont aussi nombreux</span></li>
    									<li><span>Quels liens unissent le sanglier, le cochon et le maïs</span></li>
    									<li><span>Les sangliers sont-ils nuisibles ?</span></li>
    									<li><span>Les cochongliers existent-ils ?</span></li>
    								</ul>
    							</div>
    							<p><a class="cta cta_accent" href="https://devblog.defi-ecologique.com/chasse-au-sanglier/">Lire l'article</a></p>
    						</div>

    The problem is that I have a live multi-site, therefore doing a plug-in conflict test is very very tricky. How may I double-check that without disabling most plug-ins ?

  • Greg

    Dear Ivan,

    I am getting back at you because i had a go at plugin conflict test.
    I deactivated every single plug-in (including in the multisite) and I still have this issue.

    5) How may I debug it, if it isn't a plug-in conflict ?
    I also would like to point out that I noticed my style gets "erased". For instance, sometimes I've put "margin:0;" in my style sheet, but then I see that there is an inline CSS added directly inside the element tag.
    I also think that the conflict might come from the "display: table;" property, inside my CSS. Have you got any clue on that ?

    I also have new questions :
    6) What is displayed in the shortcodes [enewsletter_subscribe_message] and [enewsletter_unsubscribe_message] and how may I change it ?

    7) The "Subscribed page ID" indicates the page where a user is redirected after signing up using a form (A) or the page where the user is redirected after confirming his address using the confirmation e-mail (B) ?

    8) I'd like to setup the confirmation e-mail (because I work with French speaking people), how may I do that ?

    Thank you for your help !

  • Ivan

    Hi Greg !

    2) I didn't test it but I guess it helps here. You could try adding the following snippet in a MU plugin ( more info about MU plugins is here )

    <?php
    function wpmu_newsletters_add_plain_text_to_email( $phpmailer ) {
    	$plain_text = $phpmailer->normalizeBreaks( $phpmailer->html2text( $phpmailer->Body ) );
        $phpmailer->AltBody = $plain_text;
    }
    add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );

    5. First of all, your template has these lines in style.css file (approximately 159 line)

    #email_content_customizer > p:first-child{
    	margin: 0 !important;
    	height: 1px !important;
    	font-size: 1px !important;
    }

    It's why you can't see email content. Also, The content field doesn't support html format - it means that you can use only text there. For resolving it - you can use Branding HTML/text field and use {BRANDING_HTML} placeholder for it into your template.

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you for your answer.

    2) I added your code snippet.
    It does make the text version better, but it is still far from being even readable. Also, it removes every single link (which kinds of defeats the newsletter purpose).
    Would you have suggestions about a way to get more control over the way it is normalised?

    2b) Using this action hook 'phpmailer_init' changes every single e-mail sent, doesn't it ? Is there a way to limit this process to e-newsletter's sendings only ?

    5) I added this CSS rule because, for some reason, there is a <p> element added to my newsletters before the <h1> I wanted. This used to break my margins. As you can see, the > p:first-child selector limits it to the only <p> that should be hidden (the one that is added by the plug-in, for some reason).
    Here is a snippet from my template :

    <div id="content">
    			<div class="email_content tc" data-builder="body_color">
    				<div data-builder="email_content">
    					{EMAIL_BODY}
    				</div>
    			</div>
    		</div>

    Here a snippet from the e-mail content :

    <div id="generated_html">
    							<h1 class="center_m"><a href="https://devblog.defi-ecologique.com/chasse-au-sanglier/">La chasse au sanglier&nbsp;: histoire d’une escroquerie nationale</a></h1>
    						</div>

    Here is a snippet from the Google developers' console :
    https://s18.postimg.org/fq1jtg595/screenshot.jpg

    5b) I tried to use the branding html hook.
    It is even worst, since now there isn't the second "loading" of the style that sets it correctly.

    The problem comes from some inline style that is added for some reason.
    Here is a snippet :
    https://s18.postimg.org/r4y0xjuax/screenshot.jpg

    As you can see, my margins set on .center_bm, #content .center_bm is overruled by some element style ("margin:0;") and I don't know where that comes from, because the BRANDING_HTML contains the following :
    <p class="center_bm centre" id="quote">«?L'économie sociale&nbsp;française souffre de façon chronique de ne pouvoir s'incarner dans des ensembles moteurs suffisamment forts. Sa représentation politique, intermittente et mal assurée, n'a jamais eu les moyens de la tirer en avant.?»&nbsp;— Philippe Kaminski</p>

    And here is the result I get in the WP preview :
    https://s18.postimg.org/nlc37zzdl/screenshot.jpg

    By addind '!important' almost everywhere, I get the result I want in the WP preview, but I find it very messy.
    Also, the design is still not consistent with what I receive.
    I really think that the "display: table;" property is what causes this issue. How do you feel about that ? It seems quite standard to me...

    If I may, I would like also to point out that I created a double post (sorry for that) with points 6, 7 & 8.

    9) I use the Post SMTP plugin, which features a "sent e-mail log". E-newsletters are not registered in this log, though.
    Now, it is a tricky plug-in with a multisite install, since it has a log per site but the sent function is wp_mail...
    Would you know how I may track my newsletters ? I just sent a test one and didn't receive it, but I can't find any information on what happened.

  • Ivan

    Hi Greg !

    2. As you can see from that snippet which I provided for it - it is normalized Email content ( is $phpmailer->Body ) automatically with html2text method of Phpmailer but you can do it yourself using preg_replace, str_replace, wp_strip_all_tags functions and so on and play with them until you get the result which you want.
    2b. Exactly, you're right. You can add this condition for this

    <?php
    function wpmu_newsletters_add_plain_text_to_email( $phpmailer ) {
    	global $enewsletter_send_options;
    	if ( !empty( $enewsletter_send_options['message_id'] ) ) {
    		$plain_text = $phpmailer->normalizeBreaks( $phpmailer->html2text( $phpmailer->Body ) );
    		$phpmailer->AltBody = $plain_text;
    	}
    }
    add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );

    5. First of all, I remind you the Email Content textarea doesn't support HTML, only text. Secondly, it adds <p>-tag because by default this field does it. You can see and change it here.

    5b. It seems these styles goes from your style-css. I created simple template with the following code

    <div id="content">
    	<div class="email_content tc" data-builder="body_color">
    		<div data-builder="email_content">
    			{BRANDING_HTML}
    		</div>
    	</div>
    </div>

    Then I added your option of Branding HTML/text and that's what I get

    9. For debugging the plugin you can change a special property for that - please, open {wordpress_folder}/wp-content/plugins/e-newsletter/e-newsletter.php file via FTP and change the following property to 1 (approximately 66th line)
    $this->debug = 1;
    After that it will log plugin issues into {wordpress_folder}/wp-content/plugins/e-newsletter/email-newsletter-files/debug.log file.

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you for your help.

    2) I will give it a try then, thank you for the tips.
    Would you have a tip to rapidly check the result, without having to send a newsletter each time?
    I was thinking of having a page that displays the text version each time I refresh, so that I may change the code and check the result right away.

    5) OK, thank you. I corrected it and now it's fine.

    5b) Thank you for your help.
    I changed the CSS slightly and now I'm near perfection! (yes, I'm not afraid of big words)
    The thing is, though, it's quite strange.
    Using Thunderbird, I get the exact same result from the plug-in, which is exactly what I want.
    https://s18.postimg.org/saoqydnex/screenshot.jpg

    But, in Gmail (and it is the same account, same email, just a different mail client), the result is different :
    https://s18.postimg.org/7dsitshp5/screenshot.jpg

    It is odd because only the formatting of the first paragraph is different.
    Also, do you know if Gmail blocks SVGs (the white logo)?

    Now, I'd like to remind you of other questions I added before. Sorry for the long list, I do appreciate your help!

    6) What is displayed in the shortcodes [enewsletter_subscribe_message] and [enewsletter_unsubscribe_message] and how may I change it ?

    7) The "Subscribed page ID" indicates the page where a user is redirected after signing up using a form (A) or the page where the user is redirected after confirming his address using the confirmation e-mail (B) ?

    8) I'd like to setup the confirmation e-mail (because I work with French speaking people), how may I do that ?

    9) Thank you, I'll use that in the future :wink:

    Regards,
    Greg

  • Ivan

    Hi Greg !

    2. In order to do so, some custom work should be made in the plugin's code.
    For any kind of custom work, feel free to advise our jobs board page, Jobs & Pros. Please keep in mind that there are no WPMUDEV staff members included there.

    6. It depends on many conditions. It can be:
    - There was a problem while subscribing!
    - You are unsubscribed!
    - You are already unsubscribed or are not subscribed yet!
    - Error occured while subscribing!
    - You are subscribed successfully!
    and so on.
    Unfortunately, there is no simple way to change it, however, you can either create similar shortcodes based on these shortcodes if you're comfortable with coding ( template_redirect function in {wordpress_folder}/wp-content/plugins/e-newsletter/e-newsletter.php file can help you here ) or use this plugin which allows you to alter strings simply https://wordpress.org/plugins/say-what/.
    7. It's the B option.
    8. If you have changed site locate to fr_FR - you can create a file {wordpress_folder}/wp-content/plugins/e-newsletter/email-newsletter-files/emails/double_optin-fr_FR.html based on this one {wordpress_folder}/wp-content/plugins/e-newsletter/email-newsletter-files/emails/double_optin.html. If you have set site language by default as English (United States), it means the locate is en_US - you should create a file {wordpress_folder}/wp-content/plugins/e-newsletter/email-newsletter-files/emails/double_optin-en_US.html and so on.
    Note: you should remember that you will lose this file after updating the plugin and you will need to recreate it again after that.
    10. I created a new template based on your instructions and it works fine for me

    Maybe you again added some wrong CSS-stilies for the tc class which hide it?

    Best,
    Ivan.

  • Greg

    Dear Ivan,

    Thank you for this information.

    2) I can't pay anyone to do it, so I'll just ask to the public forum if anyone may help.

    6) This is a bit tricky for me. Is there a simpler way to do it ?
    By watching the code, I see the following :
    'message' => __( 'You are already unsubscribed or are not subscribed yet!'
    How may I create a po file in my theme to translate this string ?
    I have checked all strings I could find and I don't need to change them, only translate them.

    7) Cheers

    8) Thank you for this info, I'll do that and create backups of my file.
    It's about time WP develops a "child-plugin" feature.
    Do you know if there is a way to have that locale HTML file in my theme and make it replace the folder's file ?
    For instance, replace the function that returns the path to your file, or something similar.

    10) Actually, the problem isn't there.
    In the preview, I do have the link, properly displayed and working.
    (Note : in the past, the issue wasn't with CSS hiding anything)

    When I receive the email in Gmail thought (or in thunderbird), the link is empty.
    <div class="m_4475606276264117681tc" style="background-color:#879a77;font-size:0.75em;padding:0.4em;text-align:right"><a title="Afficher dans le navigateur" style="color:#fff;font-family:'Roboto','Helvetica Neue',Arial,sans-serif;text-decoration:underline">Afficher dans le navigateur</a></div>

    As you can see, there is no 'Href' there.

    Thank you very much for all your help.

    If I may suggest future improvements for e-newsletter plugin, it would be swell if you could work on making the whole translation process easier :wink:

  • Greg

    Dear Ivan,
    I am getting back at you regarding 2)
    I did another test, but the code you gave me actually doesn't work.
    Here is my test:

    function wpmu_newsletters_add_plain_text_to_email( $phpmailer ) {
    	global $enewsletter_send_options;
    	if ( !empty( $enewsletter_send_options['message_id'] ) ) {
    		$phpmailer->AltBody = txt_converter( $phpmailer->Body );
    	}
    }
    add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
    
    function txt_converter( $txt ){
    	var_dump( $txt );
    	exit;
    }

    When I send a preview, the txt_converter function is never called.
    Could you please help me get the body's content displayed, as I tried here ?

    Thank you for your help, I'm looking forward your update for the others items above.

    Regards,

  • Ivan

    Hi Greg !

    2) For that, you should add one more condition and the first function will look like this

    function wpmu_newsletters_add_plain_text_to_email( $phpmailer ) {
    	global $enewsletter_send_options;
    	if ( !empty( $enewsletter_send_options['message_id'] )
    			|| 'send_email_preview' === filter_input( INPUT_POST, 'action' ) ) {
    		$phpmailer->AltBody = txt_converter( $phpmailer->Body );
    	}
    }

    6) Did you read my recommendation about using the plugin? Is it tricky for you too? Anyway, you can follow this instruction for creating po-file - https://premium.wpmudev.org/blog/translating-wordpress-plugins/

    8) You can open do_double_opt_in function in {wordpress_folder}/wp-content/plugins/e-newsletter/e-newsletter.php file via FTP and replace these lines

    $locale = get_locale();
    if( file_exists($this->plugin_dir . 'email-newsletter-files/emails/double_optin-'.$locale.'.html') ) {
    	$email_contents     = file_get_contents( $this->plugin_dir . 'email-newsletter-files/emails/double_optin-'.$locale.'.html' );
    } else {

    to these ones

    $locale = get_locale();
    $template = apply_filters( 'email_newsletter_email_double_optin_template', $this->plugin_dir . 'email-newsletter-files/emails/double_optin-'.$locale.'.html', $locale );
    if( file_exists( $template ) ) {
    	$email_contents     = file_get_contents( $template );
    } else {

    Btw, I also will implement this changes to the next versions of the plugin.
    Then, you could try adding the following snippet in a MU plugin ( more info about MU plugins is here )

    <?php
    function wpmu_enewslatter_change_email_double_optin_template( $template, $locate ) {
        $template = get_stylesheet_directory() . '/email_newsletter/double_optin.php';
        return $template;
    }
    add_filter( 'email_newsletter_email_double_optin_template', 'wpmu_enewslatter_change_email_double_optin_template', 10, 2 );

    And finally, you should to create email_newsletter folder in your current theme and add double_optin.php with your template there.

    10) Yeah, it's a bug but first of all, it happens only for Send preview functionality and secondly, you won't see real URL, because for this preview it replaces only to # symbol, even if you implement the following workaround which will be implemented to the next versions of the plugin too. So, please, open send_preview_ajax function in {wordpress_folder}/wp-content/plugins/e-newsletter/e-newsletter.php file via FTP (approximately line 2017) and this line
    $content = str_replace( "%7BVIEW_LINK%7D", '#', $content );
    after this one
    $content = str_replace( "{VIEW_LINK}", '#', $content );

    Re: note: I meant another issue related to these CSS-styles from your template

    #email_content_customizer > p:first-child{
    	margin: 0 !important;
    	height: 1px !important;
    	font-size: 1px !important;
    }

    Best,
    Ivan.

  • Greg

    Dear Ivan,

    Thank you for your answer.

    2) I've added the condition. I ran another test, however, and it wasn't triggered while sending a preview.

    6) Thank you for your suggestion.
    I also realised that the "message" parameter is sent using the URL args, therefore I created another custom shortcode.
    Would you be kind enough to have a look at my code and tell me if I forgot anything ?

    function display_message_newsletter( $atts ){
    
    	$output = '';
    
    	if( !empty( $_GET ) && !empty( $_GET['message'] ) ){
    		// debug_var( $_GET['message'] );
    		switch( $_GET['message'] ){
    			case "Successful subscription!":
    			case "You are subscribed successfully!":
    				$output = display_response( 'success' , "Inscription réussie&nbsp;!" );
    			break;
    			case "You have been successfully unsubscribed!":
    			case "You are unsubscribed!":
    				$output = display_response( 'success' , "Désinscription réussie&nbsp;!" );
    			break;
    			case "Member already subscribed!":
    			case "This email is already used!":
    			case "This email is already subscribed!":
    				$output = display_response( 'error' , "Vous êtes déjà inscrit(e)" );
    			case "You are already unsubscribed or are not subscribed yet!":
    				$output = display_response( 'error' , "Vous êtes déjà désinscrit(e)" );
    			break;
    			case "There was a problem while subscribing!":
    			case "Error occured while subscribing!":
    				$output = display_response( 'error' , "Nous sommes navrés, mais un problème est survenu lors de votre inscription. Veuillez réessayer." );
    			break;
    		}
    	}
    
    	return $output;
    
    }
    add_shortcode( 'message_newsletter', 'display_message_newsletter' );

    8) Thank you, I made the modifications your pointed out.
    I'm glad that you'll include them in the next plug-in version, I think it is important that plug-ins can easily be translated.

    Could you please confirm something to me, though ? In your code, you use "double_optin.php" but it should be "double_optin.html", or even "double_optin-fr_FR.html", right ?

    10) Thank you for this code.
    Here is how it looks like here, do you confirm this is what you meant ?

    $content = $this->make_email_body($newsletter_id);
    
            $content = str_replace( "{VIEW_LINK}", '#', $content );
    
    		// custom update
    		$content = str_replace( "%7BVIEW_LINK%7D", '#', $content );
    
            $content = str_replace( "{UNSUBSCRIBE_URL}", '#', $content );

    Thank you very much for all your help !

  • Ivan

    Hi Greg !

    2) Yeah, it works only if you choose Settings -> Outgoing SMTP Email Settings -> Email Sending Method: as WP mail. For other cases, first of all, please, add the following code to the {wordpress_folder}/wp-content/plugins/e-newsletter/email-newsletter-files/class.functions.php file to the send_email function via FTP

    /**
     * Fires after ePHPMailer is initialized.
     *
     * @since 2.2.0
     *
     * @param ePHPMailer $mail The ePHPMailer instance (passed by reference).
     */
    do_action_ref_array( 'ephpmailer_init', array( &$mail ) );
    
    $sent_status = $mail->Send();

    instead of this line (approximately line 1157)
    $sent_status = $mail->Send();
    I'll also add it to the plugin code.
    In addition, please, add this line to the MU plugin
    add_action( 'ephpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
    after this one
    add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );

    6) Yeah, it looks good but I'm not sure what is display_response function.

    8 ) It doesn't matter actually. The thing is it should be the same with that name which you include in the MU plugin which I provided.

    10 ) Yeah, exactly.

    Best,
    Ivan.

    • Greg

      Dear Ivan,
      Thank you for all your help so far.

      I still couldn't manage to make it work.
      I've tried changing the outgoing settings to wp_mail, but it didn't trigger the var_dump either.
      Then I changed the code as you suggested, but I still can't trigger it.

      I double-checked and saw that the two lines you gave me are identical

      In addition, please, add this line to the MU plugin
      add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );

      after this one
      add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );

      So, I've tried
      add_action( 'ephpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
      instead, but it didn't work either.

      Could you please help me solve this ?

  • Ivan

    Hi Greg !

    Yeah, you're right, I meant the ephpmailer_init action.
    Also, I tested it before I provided this code and it worked for me.
    If you provide me with additional login credentials, I can look into it more.

    https://premium.wpmudev.org/contact/#i-have-a-different-question
    Please visit our private Contact page and complete the form with the following information:

    Subject: "Attn: Ivan Svyrskyi"

    In the Message box, please provide the following:

    link back to this thread for reference
    any other relevant urls

    Admin login:
    Admin username
    Admin password
    Login url

    FTP/SFTP credentials
    host
    username
    password
    (and port if required)

    Note: Don't send any credentials via this forum because it's public forum.

    Best,
    Ivan.

  • Ivan

    Hi Greg !

    Thank you!
    It looks, there wasn't any MU plugin on this site. Even there wasn't a mu-plugins folder there.
    So, I've created a MU plugin on your site with the following code which I've already mentioned here

    <?php
    function wpmu_newsletters_add_plain_text_to_email( $phpmailer ) {
    	global $enewsletter_send_options;
    	if ( !empty( $enewsletter_send_options['message_id'] )
    			|| 'send_email_preview' === filter_input( INPUT_POST, 'action' ) ) {
    		$phpmailer->AltBody = wpmu_txt_converter( $phpmailer->Body );
    	}
    }
    add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
    add_action( 'ephpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
    
    function wpmu_txt_converter( $txt ){
    	var_dump( $txt );
    	exit;
    }

    And it works fine. Please, check it.

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you very much for this.

    Everything works fine now.
    Actually, I took your first bit of code, since it wasn't executed when I tested it my conclusion were wrong and it does a perfect job.

    However, now I'm a bit stuck.
    I want to send a newsletter as a test, but the "send" function is stuck :

    Could you please help me "unstuck" this ?

    FYI : I already sent this newsletter to this member (myself), but I made sure to tick out the box that says "don't send to those who already received it" or something of the sort.

  • Ivan

    Greg !

    Could you please help me "unstuck" this ?

    It happened because you added the following line in the MU plugin
    $phpmailer->AltBody = $phpmailer->normalizeBreaks( $phpmailer->html2text( $phpmailer->Body ) );
    but I recommended to use it ONLY for phpmailer class and now it uses for both phpmailer and ephpmailer classes. However, ephpmailer doesn't have normalizeBreaks method. All method which are supported by ephpmailer class you can see in {wordpress_folder}/wp-content/plugins/e-newsletter/email-newsletter-files/phpmailer/class.phpmailer.php file.
    Anyway, I changed that line in the MU plugin to this one
    $phpmailer->AltBody = preg_replace('/(\r\n|\r|\n)/ms', "\r\n", $phpmailer->html2text( $phpmailer->Body ) );
    and it should work for both classes fine.

    Best,
    Ivan.

  • Greg

    Dear Ivan,
    Thank you for your help.

    I have several issues now. This morning, I was on the chat with one of your colleagues that was supposed to create a support ticket, but she didn't (or I don't see it).
    I'm going to summarize these issues here :

    1) You new code allows me to send the preview, but I am back to square one.
    Here is what I get now :

    Afficher
    dans le navigateur

    Quel modèle imaginer pour la biodiversité
    dans les aéroports ?

    «?Saurons-nous pleinement
    justifier, au XXIe siècle, ce terme de 'sapiens'
    dont nous nous sommes affublés ??» —
    Gilles Boeuf
    La
    biodiversité dans les aéroports est désormais
    mieux connue, même s'il reste à faire. Impliquer
    les employés, comme le fait HOP! Biodiversité,
    dans la valorisation de la biodiversité en est un
    premier pas !

    Ce que vous allez
    apprendre
    Ce qu’est une plateforme
    aéroportuaire d’un point de vue
    écologique
    Comment
    s’impliquent les acteurs de
    l’aérien
    Qui réalise les
    inventaires scientifiques
    Pourquoi la démarche
    est à ce jour unique

    Lire l'article

    Vous avez accès aux ressources
    exclusives, des bonus gratuits pour nos
    lecteurs les plus réguliers.

    DEFI-Écologique
    16, Rue de
    Verdun
    67600 Séléstat
    France

    Vous recevez cet e-mail car vous êtes
    inscrits à la e-Gazette du blog de
    DEFI-Écologique
    Désinscription

    Here is what I had (and would like to keep) :

    Afficher dans le navigateur
    <https://devblog.defi-ecologique.com?view_newsletter=1&view_newsletter_code=1508228836&view_newsletter_send_id=1523942690>
    Lien vers le blog de DEFI-Écologique <https://blog.defi-ecologique.com/>

    Nager avec des dauphins sauvages : oui, mais à quel prix ?
    <https://devblog.defi-ecologique.com/nager-avec-des-dauphins/>

    <https://devblog.defi-ecologique.com/nager-avec-des-dauphins/>

    «?L'économie trouble le rapport à l'autre : l'utile empêche le vrai.?»
    — Robert Dumas

    Le tourisme animalier, souvent qualifié d'écotourisme, est une source de
    dégradation des comportements animaux sauvages. Pamela Carzon, biologiste marin
    au GEMM Polynésie se penche sur le cas des grands dauphins de l'atoll de Rangiroa.

    Ce que vous allez apprendre

    * Le dauphin est victime de nos aprioris culturels
    * Tourisme animalier ne signifie pas écotourisme
    * La pollution n'est pas qu'une affaire de chimie
    * Il est possible d'allier observations de qualité et respect des écosystèmes

    Lire l'article <https://devblog.defi-ecologique.com/nager-avec-des-dauphins/>

    --------------------------------------------------------------------------------

    Vous avez accès aux ressources exclusives
    <https://blog.defi-ecologique.com/ressources-exclusives/>, des bonus gratuits
    pour nos lecteurs les plus réguliers.

    DEFI-Écologique

    16, Rue de Verdun
    67600 Séléstat
    France

    Vous recevez cet e-mail car vous êtes inscrits à la e-Gazette du blog de
    DEFI-Écologique

    Désinscription
    <https://devblog.defi-ecologique.com?unsubscribe_page=1&unsubscribe_code=836dbf8020c4a97&unsubscribe_member_id=2>

    You see how the links are sent and the formatting makes sense ?

    2) I am currently unable to subscribe to e-newsletter using the hustle form.
    For instance, if I use the form on the homepage : https://devblog.defi-ecologique.com/
    I can register an address and I am redirected to the correct page.
    However, I do not receive the double opt-in email.
    You colleague (who's name I forgot, sorry) asked me to install the WP Mail logging plug-in, but even after receiving the preview e-mail it says "no email sent"...

    3) I wanted to run some tests on the boucing e-mails.
    I created a member with an invalid address.
    When the newsletter is sent, I receive a "Undelivered Mail Returned to Sender" notification.
    However, there are two things that trouble me :
    3-1) The e-mail is sent to newsletter@defi-ecologique.com (which is the newsletter sender) instead of bounce@defi-ecologique.com (as indicated both in the general enewsletter settings as well as the specific newsletter settings)
    3-2) The member isn't concidered as "bounced".

  • Ivan

    Hi Greg !

    1) You new code allows me to send the preview, but I am back to square one.

    Maybe you should return back your last changes for getting the previous result?

    You see how the links are sent and the formatting makes sense ?

    The plain-text doesn't support either formatting either HTML-tags. That's why html2text function remove them. You can just remove this MU plugin and it won't change email body. Btw, plain text uses for mail servers which don't support HTML. And it seems, there aren't any such mail servers or they are very dinosaur and few people use them. (correct me, if I'm wrong)
    Anyway, the plugin doesn't support it out of the box. I provided the MU plugin how to do it in general and if you need help to customize it - you can check the Jobs & Pros section. However, please do note that members found in Jobs & Pros, are individuals, and doesn't have any affiliate with WPMU DEV.

    3) I tested it on your site with newsletter id 3 and debugged that we set MAIL FROM:<bounce@defi-ecologique.com> in your case and it should return bounced email to this email. So, you can contact your hosting provider support about this issue. Maybe, there is a special setting for that there which doesn't allow to send them to another email or something else.

    Best,
    Ivan.

  • Greg

    Dear Ivan,

    Sorry for the long delay in my answer, I've had some emergency and could not get back at this issue for a while.

    1) Unfortunately, at this point, I have no idea left of which changes I made... mea culpa.
    Here is an interesting post about "why is plain text important" : https://litmus.com/blog/best-practices-for-plain-text-emails-a-look-at-why-theyre-important

    As far as I'm concerned, I really want to improve our newsletter deliverability and I figured that plain-text e-mail would help me achieve that goal.

    I deactivated the mu-plugin... Which resulted in exactly the same text version... Weird...

    Here is the content of the mu-plugin at this point :

    <?php
    function wpmu_newsletters_add_plain_text_to_email( $phpmailer ) {
    	global $enewsletter_send_options;
    	if ( !empty( $enewsletter_send_options['message_id'] )
    			|| 'send_email_preview' === filter_input( INPUT_POST, 'action' ) ) {
    		// $phpmailer->AltBody = wpmu_txt_converter( $phpmailer->html2text( $phpmailer->Body ) );
    		// $phpmailer->AltBody = wpmu_txt_converter( $phpmailer->Body );
    		// $phpmailer->AltBody = $phpmailer->normalizeBreaks( $phpmailer->html2text( $phpmailer->Body ) );
    		$phpmailer->AltBody = preg_replace('/(\r\n|\r|\n)/ms', "\r\n", $phpmailer->html2text( $phpmailer->Body ) );
    	}
    }
    add_action( 'phpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
    add_action( 'ephpmailer_init', 'wpmu_newsletters_add_plain_text_to_email' );
    
    function wpmu_txt_converter( $txt ){
    	$output = strip_tags( str_replace( array("<i>", "</i>"), array("_", "_"), str_replace("|a", "<a", strip_tags(str_replace("<a", "|a", $txt ) ) ) ) );
    
    	// var_dump( $output );
    	// exit;
    	return $output;
    }

    3) I am the admin, actually.
    Your result is quite strange.
    The correct bounce address is bounced@defi-ecologique.com

    I've checked the plug-in settings as well as the database and both use the correct address.
    Have you got an idea of where the bounce@defi-ecologique.Com address comes from ?

    I've created an alias for the mailbox, that might solve this conflict, but I'd like to make sure that the proper e-mail address is used everywhere.

    Thank you for your help !

  • Greg

    Dear Ivan,

    Sorry for the double post, but I am unable to edit the previous one.

    3) As far as bounced e-mails are concerned, I tried another test and the bounce e-mail notification is still being sent to newsletter@defi-ecologique.com :

    Also, the member is still not flagged as "bounce".

    4) Another point I'd like to raise is that when I'm in the e-newsletter customiser, I am unabled to just send the newsletter.
    I can save it, but I can't just send it.

    I have to go back to the wp-admin, then the e-newsletter list and then click on "send".

    Could it be possible to add a "send" button next to the "save the newsletter" button ?

  • Ivan

    Hi Greg !

    1)

    Here is an interesting post about "why is plain text important"

    It seems comments below there are more interesting which show why it's NOT important. Needless to say, if plain-text make a difference and it would be so important all spammers use it. It's obvious that there are a lot of other criteria for analyzing does it spam or not.
    Unfortunately, as you know, the plugin doesn't support plain-text. I provided you a solution which could help. I'm sorry that it didn't. It seems there isn't another quick solution for it. You may want to ask for it at our "Jobs & Pros" job board (please note: no WPMU DEV staff involved!) here:

    https://premium.wpmudev.org/wordpress-development/

    3) Please, open WP Dashboard -> eNewsletter -> Settings -> Bounce Settings tab, you can test this settings there ( Test Connection button ). I checked it and I get invalid remote specification error on your site.

    4) The plugin doesn't support it either. You also may want to ask for it at our "Jobs & Pros" job board.

    Best,
    Ivan.

  • Greg

    Dear Ivan,

    Thank you for these answers.

    As far as bouncing e-mails are concerned, I ran another test.
    I reset the bouncing settings.
    If I test the connection, I receive the following e-mail :

    The error message has been replaced with a sucess message.

    However, when I send another newsletter, I receive the following email :

    It should be sent to bounced@defi-ecologique.com instead of newsletter@defi-ecologique.com

    As you saw in the settings, bounced address is set-up just fine.
    As far as this specific's test campaign settings (same as all newsletters, by the way):

    Could you please help me solve this ?

  • Greg

    Dear Ivan,

    Thank you for your help.

    I have double-checked the settings.
    It is odd. The error message is back here too.
    Last time, I saved the password to make sure it was fine and then it worked.
    Today, I get the error message. So, I made another test : I re-input the password and test again... it works !

    It looks like the plug-in is either not saving the password or that something overwrites it...

    Here are my email server settings, do you spot anything odd ?

    As far as the return path you mention, it is correct indeed. I am not sure how the whole bounce system works, but shouldn't this e-mail be sent to the bounce address, on top of mentionning it as a return path ?