Jump to content

WireMailSmtp


horst

Recommended Posts

Wire Mail SMTP

An extension to the (new) WireMail base class that uses SMTP-transport

This module integrates EmailMessage, SMTP and SASL php-libraries from Manuel Lemos into ProcessWire. I use this continously evolved libraries for about 10 years now and there was never a reason or occasion not to do so. I use it nearly every day in my office for automated composing and sending personalized messages with attachments, requests for Disposition Notifications, etc. Also I have used it for sending personalized Bulkmails many times.

The WireMailSmtp module extends the new email-related WireMail base class introduced in ProcessWire 2.4.1 (while this writing, the dev-branch only).
 
Here are Ryans announcement.



Current Version 0.6.0

Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md

Install and Configure

Download the module into your site/modules/ directory and install it.

In the config page you fill in settings for the SMTP server and optionaly the (default) sender, like email address, name and signature.
You can test the smtp settings directly there. If it says "SUCCESS! SMTP settings appear to work correctly." you are ready to start using it in templates, modules or bootstrap scripts.


Usage Examples

The simplest way to use it:

$numSent = wireMail($to, $from, $subject, $textBody);

$numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page 

This will send a plain text message to each recipient.
 
You may also use the object oriented style:

$mail = wireMail(); // calling an empty wireMail() returns a wireMail object

$mail->to($toEmail, $toName);
$mail->from = $yourEmailaddress; // if you don't have set a default sender in config
                                 // or if you want to override that
$mail->subject($subject);
$mail->body($textBody);

$numSent = $mail->send();

Or chained, like everywhere in ProcessWire:

$mail = wireMail();
$numSent = $mail->to($toEmail)->subject($subject)->body($textBody)->send(); 

Additionaly to the basics there are more options available with WireMailSmtp. The main difference compared to the WireMail BaseClass is the sendSingle option. With it you can set only one To-Recipient but additional CC-Recipients.

$mail = wireMail(); 

$mail->sendSingle(true)->to($toEmail, $toName)->cc(array('person1@example.com', 'person2@example.com', 'person3@example.com')); 

$numSent = $mail->subject($subject)->body($textBody)->send(); 

The same as function call with options array:

$options = array(
    'sendSingle' => true,
    'cc' => array('person1@example.com', 'person2@example.com', 'person3@example.com')
    );

$numSent = wireMail($to, '', $subject, $textBody, $options); 

There are methods to your disposal to check if you have the right WireMail-Class and if the SMTP-settings are working:

$mail = wireMail(); 

if($mail->className != 'WireMailSmtp') {
    // Uups, wrong WireMail-Class: do something to inform the user and quit
    echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>";
    return;
}

if(!$mail->testConnection()) {
    // Connection not working:
    echo "<p>Couldn't connect to the SMTP server. Please check the {$mail->className} modules config settings!</p>";
    return;
} 

 

A MORE ADVANCED DEBUG METHOD!

You can add some debug code into a template file and call a page with it:

    $to = array('me@example.com');
    $subject = 'Wiremail-SMTP Test ' . date('H:i:s') . ' äöü ÄÖÜ ß';

    $mail = wireMail();
    if($mail->className != 'WireMailSmtp') {
        echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>";

    } else {

        $mail->from = '--INSERT YOUR SENDER ADDRESS HERE --'; // <--- !!!!

        $mail->to($to);
        $mail->subject($subject);
        $mail->sendSingle(true);

        $mail->body("Titel\n\ntext text TEXT text text\n");
        $mail->bodyHTML("<h1>Titel</h1><p>text text <strong>TEXT</strong> text text</p>");

        $dump = $mail->debugSend(1);
    }

So, in short, instead of using $mail->send(), use $mail->debugSend(1) to get output on a frontend testpage.

The output is PRE formatted and contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection, like this one:

Spoiler

Resolving SMTP server domain "XXXXXXXXXXXXXXXXXXXX"...

Connecting to SMTP server "XXXXXXXXXXXXXXXXXXXX" port 587...

Connected to SMTP server "XXXXXXXXXXXXXXXXXXXX".

S 220 XXXXXXXXXXXXXXXXXXXX ESMTP

C EHLO wiremailsmtp.kawobi.local

S 250-XXXXXXXXXXXXXXXXXXXX

S 250-PIPELINING

S 250-SIZE 102400000

S 250-VRFY

S 250-ETRN

S 250-STARTTLS

S 250-AUTH PLAIN LOGIN

S 250-AUTH=PLAIN LOGIN

S 250-ENHANCEDSTATUSCODES

S 250-8BITMIME

S 250 DSN

C STARTTLS

S 220 2.0.0 Ready to start TLS

Starting TLS cryptographic protocol

TLS started: STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT

C EHLO wiremailsmtp.kawobi.local

S 250-XXXXXXXXXXXXXXXXXXXX

S 250-PIPELINING

S 250-SIZE 102400000

S 250-VRFY

S 250-ETRN

S 250-AUTH PLAIN LOGIN

S 250-AUTH=PLAIN LOGIN

S 250-ENHANCEDSTATUSCODES

S 250-8BITMIME

S 250 DSN

C AUTH PLAIN XXXXXXXXXXXXXXXXXXXX

S 235 2.7.0 Authentication successful

C MAIL FROM:<XXXXXXXXXXXXXXXXXXXX>

C RCPT TO:<XXXXXXXXXXXXXXXXXXXX>

C DATA

S 250 2.1.0 Ok

S 250 2.1.5 Ok

S 354 End data with <CR><LF>.<CR><LF>

C To:  <XXXXXXXXXXXXXXXXXXXX>


Subject: Wiremail-SMTP Test 08:41:31 =?UTF-8?q?=C3=A4=C3=B6=C3=BC_=C3=84=C3=96=C3=9C_=C3=9F?=


From: LocalTestmail <XXXXXXXXXXXXXXXXXXXX>


Return-Path: XXXXXXXXXXXXXXXXXXXX


Reply-To:  <XXXXXXXXXXXXXXXXXXXX>


X-Mailer: ProcessWire/WireMailSmtp


Date: Mon, 28 Oct 2019 07:41:32 GMT


MIME-Version: 1.0


Content-Type: multipart/alternative; boundary="dbbe5bbf21a410f0b110683a0afec17a"


Message-ID: <20191028084132.3800.XXXXXXXXXXXXXXXXXXXX>







C --dbbe5bbf21a410f0b110683a0afec17a


Content-Type: text/plain; charset=UTF-8


Content-Transfer-Encoding: quoted-printable





Titel=0A=0Atext text TEXT text text=0A


--dbbe5bbf21a410f0b110683a0afec17a


Content-Type: text/html; charset=UTF-8


Content-Transfer-Encoding: quoted-printable





<h1>Titel</h1><p>text text <strong>TEXT</strong> text text</p>


--dbbe5bbf21a410f0b110683a0afec17a--




C 


.

S 250 2.0.0 Ok: queued as XXXXXXXXXXXX

C QUIT

S 221 2.0.0 Bye

Disconnected.

 

 

Following are a ...


List of all options and features


testConnection () - returns true on success, false on failures


sendSingle ( true | false ) - default is false

sendBulk ( true | false ) - default is false, Set this to true if you have lots of recipients (50+)


to ($recipients) - one emailaddress or array with multiple emailaddresses

cc ($recipients) - only available with mode sendSingle, one emailaddress or array with multiple emailaddresses

bcc ($recipients) - one emailaddress or array with multiple emailaddresses

 
from = 'person@example.com' - emailaddress, can be set in module config (called Sender Emailaddress) but it can be overwritten here

fromName = 'Name Surname' - optional, can be set in module config (called Sender Name) but it can be overwritten here


priority (3) - 1 = Highest | 2 = High | 3 = Normal | 4 = Low | 5 = Lowest

dispositionNotification () or notification () - request a Disposition Notification


subject ($subject) - subject of the message

body ($textBody) - use this one alone to create and send plainText emailmessages

bodyHTML ($htmlBody) - use this to create a Multipart Alternative Emailmessage (containing a HTML-Part and a Plaintext-Part as fallback)

addSignature ( true | false ) - the default-behave is selectable in config screen, this can be overridden here
(only available if a signature is defined in the config screen)

attachment ($filename, $alternativeBasename = "") - add attachment file, optionally alternative basename


send () - send the message(s) and return number of successful sent messages



debugSend(1) - returns and / or outputs a (pre formatted) dump that contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection. (See above the example code under ADVANCED DEBUG METHOD for further instructions!)



getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,


logActivity ($logmessage) - you may log success if you want

logError ($logmessage) - you may log warnings, too. - Errors are logged automaticaly
 
 
useSentLog (true | false) - intended for usage with e.g. third party newsletter modules - tells the send() method to make usage of the sentLog-methods - the following three sentLog methods are hookable, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here

sentLogReset ()  - starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter

sentLogGet ()  - is called automaticly within the send() method - returns an array containing all previously used emailaddresses

sentLogAdd ($emailaddress)  - is called automaticly within the send() method

Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md

 

 

Edited by horst
bumped to version 0.6.0
  • Like 29
Link to comment
Share on other sites

Thanks for making this Horst! Tested here and got it working. I did have to modify your to() function (my fault, since I changed the WireMail interface for that function in the last update), but that was easy, and everything else worked (testing it with Gmail). I particularly liked being able to test the settings from the module screen.

Your getModuleInfo() returns singular=true.  The intention with WireMail is that it would be singular=false, so that you'd start with a new/fresh instance every time you get it from wireMail() or $modules->get('WireMailSmtp'). Otherwise, it might already have the to/from/subject/body settings from the last use still in there. 

Why necessary to specify the sender email address in the module settings? Will this prevent someone from being able to change the $mail->from(); address from the API side? Also was wondering why it's necessary to specify the hostname in the module settings? Does it go into an envelope from header or something? 

  • Like 1
Link to comment
Share on other sites

Thanks for making this Horst! Tested here and got it working. I did have to modify your to() function (my fault, since I changed the WireMail interface for that function in the last update), but that was easy, and everything else worked (testing it with Gmail). I particularly liked being able to test the settings from the module screen.

Your getModuleInfo() returns singular=true. The intention with WireMail is that it would be singular=false, so that you'd start with a new/fresh instance every time you get it from wireMail() or $modules->get('WireMailSmtp'). Otherwise, it might already have the to/from/subject/body settings from the last use still in there.

Yes have read it in SwiftMailer-Thread before. I will update the module after posting this.  :)

Also have allready downloaded a fresh wire folder from Github.

Why necessary to specify the sender email address in the module settings? Will this prevent someone from being able to change the $mail->from(); address from the API side?

Lazyness! If using the object->style (not the procedural function call), there is no need to specify it when a default sender is set in config settings. But it could be overwritten by the $mail->from. Maybe I should make it an optional setting, not a required one.

I have thought of a setting that prevents overwriting settings from the config screen. Default Sender is the only one valid. Recipients could be a whitelist (currently a textarea under tab advanced) and a checkbox to include emailaddresses from PW users or not. If a security restriction like this is implemented and checked, mails only get send to recipients from the valid_recipients list.

Is this a useful feature?

Also was wondering why it's necessary to specify the hostname in the module settings? Does it go into an envelope from header or something?

This is used when connecting to the SMTP-Server. You find it as the first entry in the Received header of every received mail. For example my local test account is called pw4.kawobi.local, this is what the headers look:

Return-Path: <xxxx@xxxxxxx.xx>
X-Original-To: xxxx@xxxxxxx.xx
Received: from pw4.kawobi.local (dslb-084-099-066-105.t-online [84.99.66.105])
	by xyz1234.smtpserver.com (Postfix) with ESMTPSA id 5EDBC2C004E6
	for <xxxx@xxxxxxx.xx>; Mon,  3 Mar 2014 19:00:10 +0100 (CET)
To: Peter Mueller <xxxx@xxxxxxx.xx>
Subject: WireMailSmtp Test MultipartAlternative

As far as I know, this is common usage, but with most clients you cannot influence the chosen name.

EDIT: Module is updated to v0.0.4, look into the first post please. :)

  • Like 2
Link to comment
Share on other sites

I have updated the class to version 0.0.5 and also have edited the first post of this thread (added some short examples and a list of available options/methods).

Now per default the module sends multiple messages in a loop, (one for each TO-recipient) like the base class do.

Additionaly you can call sendBulk to send larger amount of messages at once in an optimized manner, - or you can call sendSingle to set the module to allow only one TO-recipient but additionally CC-recipients. More information are now in the first post here.

  • Like 6
Link to comment
Share on other sites

Hhm, sorry! With the 0.0.5 I have added a configuration option that lets you choose when an optional MailSignature should be send, but have left a boolean true somewhere in the code that overrides always these setting. :-[

Have corrected this now and committed the v 0.0.6 to GitHub. (ZIP)

  • Like 2
Link to comment
Share on other sites

Yes it is. I think with Ryan's changes given to all email-related stuff it is much easier as of it was as we have talked about it.

If I remember right, you call only at one point in your code php's mail function. This part maybe get reorganized depending of if it is called a single time (then it is just fine to pass all recipients into wireMail at this point) or if it is within a loop (called multiple times), than you have to change this.

You have to pass $options array('sendBulk'=>true) with the wireMail($to, $from, $subject, $textBody, $options);

You need to update the wire folder to 2.4.1 (the current dev branch)!

EDIT:

There is only rare support built in for bulk mail sending, at least when focusing on robustness and comfortable handling of large amounts.

Actually there is only a check in it that skips duplicate emailaddress entries. Actually it is needed that the script runs within one request from start to end. If it gets interrupted somehow you end up in a mess. I think it is fine to use it with small amounts of recipients actually (0-200).

Oh, - while writing here I got an idea how to implement a simple hookable feedback for that. I will try this and add it to the module if it comes out functional.

EDIT2: added! see next post :)

Link to comment
Share on other sites

updated to version 0.0.7

Added a new flag that tells the send() method to make usage of the new logging methods for handling large amounts of recipients by using permanent storage across multiple script calls:

  • useSentLog( true | false )
    Tells the send()-method to make usage of the SentLog-methods! 
     
  • sentLogReset()
    It starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter.
     
  • sentLogGet()
    is called automaticly by the send() method - returns an array containing all previously used emailaddresses
     
  • sentLogAdd($emailaddress)
    is called automaticly by the send() method - stores each successfully sent emailaddress into the provided log

This is intended to use within third party modules for newsletter systems. All three sentLog methods are made hookable, so, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here.

The usage is really simple, I think. When starting a new Newsletter Session, you once have to call wireMail()->sentLogReset() to clear any previously stored content in the log. This best should be done manually / interactively I think.

After that you only have to set the useSentLog flag to true, e.g by passing an options array into the procedural function call

$options = array(
    'sendBulk' => true,
    'useSentLog' => true
    );

$numSent = wireMail($to, $from, $textBody, $options);

or in object-oriented style like this

$numSent = wireMail()->sendBulk(true)->useSentLog(true)->to($to)->from($from)->body($textBody)->send();

That's all. Now you can call your newsletter sending script multiple times (for example bind to lazy cron) and no recipient get lost nor will receive multiple messages.

No more worries about script timeouts or other interruptions, just call your script in regular intervals, but ensure that only one instance is running at the time and not multiple in parallel. It would not mess up the logfile because it uses filelocking, but you may get trouble with your SMTP provider if you stress the server. :lol:

PS: @Nico: want to test it in the near future?

  • Like 7
Link to comment
Share on other sites

Hello horst, i have installed and tried WireMailSmtp too and installing and sending mail works fine.

But i also noted that sending a form with more then 1 file field will send only a link to the first attachment. The second attachment is always 0b (in the email body). While in the FormBuilder Entries both files are uploaded correctly.

Seems like a little bug in the WireMail class processing the second file field incorrectly.

Link to comment
Share on other sites

I don't know FormBuilder.

wireMail()->attachment() needs an absolute path for every (disk) file it should attach to a message. You can pass it as array or have to call it multiple times. Here are all is working as expected.

Maybe you can debug what is passed to the attachment function when running with FormBuilder?

You can call a log here

wire('log')->save( "debug_attachments", strtolower(__FUNCTION__).' :: '.serialize($filenames));   // ATTENTION this is $filename(s) ending with s

and here

wire('log')->save( "debug_attachments", strtolower(__FUNCTION__).' :: '.serialize($filename));   // ATTENTION this is $filename, without s

Trying this with passing an array logs something like:

2014-03-11 14:04:36	guest	http://pw4.kawobi.local/mailtest/	attachments :: a:2:{i:0;s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";i:1;s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";}
2014-03-11 14:04:36	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";
2014-03-11 14:04:36	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";

Calling it multiple times (2) with string filenames:

2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachments :: s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";
2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachments :: s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";
2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";
2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";
  • Like 3
Link to comment
Share on other sites

@horst thank you for helping and pointing out a way to log the file names to see what is going on.

I have placed both lines inside the WireMailSmtp.module and posted the form a few times to find out that nothing is logged. The code is right because putting the following line in the __construct() created the expected log file correctly.

wire('log')->save( "debug_attachments", "tralalala");
I came to the conclusion that form builder is not realy sending the files as attachments. All it does is save the attachments to /assets/cache/form-builder/form-x/entry-x/ and rendering a 'special' link to those files. So now i'm sure the bug is form-builder related and not in your WireMailSmtp and/or WireMailSwiftMailer module.

I will report it in the form-builder forum and see if i can find out something more to backup the bug report with.

Update: Haha Ryan is always 3 steps ahead :) I found this line in InputfieldFormBuilderFile.module

// @todo this is producing invalid file links when more than one file on the page

Edited by Raymond Geerts
  • Like 3
Link to comment
Share on other sites

@Raymond: I don't know how FormBuilder works, where and how you can connect the uploaded files to the WireMail classes. If you find a solution it would be kind if you can post it here.

Link to comment
Share on other sites

  • 3 months later...

hi horst, thank you for this module, works great.

i'm interested in the "You can hook into it if you want use alternative stores for it" thing from a template to get a sentlog for each page, can you give me a tip how to achieve this?

Link to comment
Share on other sites

ah ok, works this way.

wire()->addHook("wireMail::sentLogReset", function(HookEvent $event) {	
		$filename = wire('config')->paths->logs . 'wiremailsmtp_sentlog_' .wire('page')->name. '.txt';
		@touch($filename);
		$res = file_put_contents($filename, '', LOCK_EX );
		if(false===$res || 0!==$res || !file_exists($filename) || !is_readable($filename) || !is_writeable($filename)) {
			$this->logError('Cannot reset Content of the SentLog: ' . $filename);
			throw new WireException('You want to make usage of the SentLog-feature, but cannot reset Content of the SentLog: ' . basename($filename));
		}
		$event->replace = true;
		$event->return = 0===$res ? true : false;	
	
});
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

@Horst,

great module, many thanks for your work on this! Got attachments sending and works perfectly....

Got a couple of questions; first thing is that my email client is showing the wrong time sent on the emails, specifically Outlook for Mac; webmail, apple mail and android mail are all showing the correct sent time; just wondering why Outlook is showing the sent time as 4 hours before the actual time sent - could it be interpreting the headers differently? Other than these messages sent by WiremailSMTP, outlook shows the correct time sent...

** Update - i'm now using mandrill for the smtp and this has fixed the time being wrong on Outlook; not sure if it is the server, or if Mandrill is cleaning up/altering some part of the email code itself;

2nd question is how might i use logActivity ($logmessage) to save that activity into a textarea field on my processwire page that the email is generating from?; would be cool to show a field with the send log right on that page;

another question which isn't really directly related to the module, is how one might use images within the RTE and be able to have the email display the images; it would require replacing the relative image paths in TinyMCE with the absolute paths, but i'm not sure how to get started on that...[for now i have a hanna code that inserts the site's base path; kills the image in the editor, but it shows in the email...

Link to comment
Share on other sites

I finally got around to installing and configuring this module today.  Thank you for making this available as a ProcessWire module.  Everything worked fine and you should be commended for a quality piece of work.

  • Like 1
Link to comment
Share on other sites

Got a couple of questions; first thing is that my email client is showing the wrong time sent on the emails, specifically Outlook for Mac; webmail, apple mail and android mail are all showing the correct sent time; just wondering why Outlook is showing the sent time as 4 hours before the actual time sent - could it be interpreting the headers differently? Other than these messages sent by WiremailSMTP, outlook shows the correct time sent...

The Date header what is sent together with the emails is configured this way:

date("D, j M Y H:i:s \G\M\T P")

It results in the current GMT and the local difference in P.

AFAIK that's the common way according to the RFCs.

2nd question is how might i use logActivity ($logmessage) to save that activity into a textarea field on my processwire page that the email is generating from?; would be cool to show a field with the send log right on that page;

logActivity isn't meant to hook into. But you can get data from the logfile with tail() or something.

The logfile is under $config->paths->logs . WireMailSmtp::LOG_FILENAME_ACTIVITY . '.txt'

Edited by horst
  • Like 4
Link to comment
Share on other sites

@horst - thanks, this time difference thing is probably related to the actual server location vs the config->timezone ? does your module use the config->timezone setting to set that?

regarding the whole logging thing, i feel stupid, i'm pretty much lost even after reading this thread 5 times... no idea how to simply log the success of a mail being sent, either to a log file, or to a field on my page... for now i do this which is ok for the moment:

                        // Send
                        $sendLog = 'Number Sent: ';
                        $sendLog .=    $mail->send();
                        
                        // Logging
                        $email_log = $message->email_log;
                        $email_log .= "\n". $sendLog;
                        $message->email_log = $email_log;
                        $message->of(false);
                        $message->save();
Link to comment
Share on other sites

@Macrura: regarding the logging, there are already functions that do the logging into files if you enable it like explained here.

If you don't want use the default logging files, you need to hook into the logging functions by e.g. creating a module with your logging functions or by defining the hooks on a template like MartinD described here.

But can you explain a bit more how you setup your mail recipients? How many recipients do you use (bulk or single)?

If you use bulk sending, do you have an admin page where you initialize the mail sending? (add / select recipients to / from a collection?)

Or do you prefer to do this ((partially) hardcoded?) in a template file only?

I can write some lines of example code if I know a bit more of your setup. :)

EDIT:

regarding the Date Header: https://github.com/horst-n/WireMailSmtp/blob/master/WireMailSmtpAdaptor.php#L351

It simply uses the PHP date function to output the current date-time. But you may try using the php gmdate function instead and look if it solves the issue.

You simply need to change date to gmdate in line 351 of WireMailSmtpAdaptor.php.

Edited by horst
forgot to answer to the date thing
  • Like 1
Link to comment
Share on other sites

Hi Horst -

thanks ! i'm using PW pages for the email and i have contacts stored in pages and then i can use asmselect for choosing who to send to, 1 or more...

so for multiple i use the recipients array

// Recipients
if($message->recipients->count()) {
	$recipients = array();
	foreach($message->recipients as $recipient) {
		$recipients[] = $recipient->title . ' <' . $recipient->email . '>';
		}
	$mail->to($recipients); 
} 

but i was thinking that I want to personalize the emails, so i would need to refactor the code to start a loop with the recipients and then run a string replace on the {{name}} placeholder in the email...

how does this relate to the bulk option?

thanks also about the gmdate  - will look at that tonight..

cheers!

Link to comment
Share on other sites

i think what was happening then with the date/time is that it is getting server time, as opposed to processwire time..

$this->emailMessage->SetHeader("Date", date("D, j M Y H:i:s \G\M\T P"));

so the problem could be for someone who is using a server in a different timezone

could we override this at the template/api level?
 

Also  - to elaborate more on this use case: last year i found it necessary to setup future sending emails to some clients (hosting invoices, payment plans etc..) and the only solution i could come up with was a service called LetterMeLater; but i thought while using it, that it would not be so hard to build this in processwire... so after about 2 hrs of setup i was able to replicate that and it works well, better than the original service i was using;

some features I've been able to accomplish over the last few days of creating this:

  • Select Identity to send from (and then uses that identity's signature)
  • Select multiple recipients
  • using a profields table, setup a schedule of sending, along with placeholder texts for each sending instance
  • Attachments to the message (page)
  • Attachments from a central repository of attachments
  • Links to documents/media
  • Render inline images in body and signatures (using string replacements for the image urls - prepending the site URL), also floating images are working
  • List of attached documents
  • Send offset (so you can select a due date and then offset to send the message X days early; this way you can set the dates in the table to the due dates and avoid date confusion)
  • Boilerplate insertion (select from an array of generic pre-written 'boilerplate' texts and insert them..)

this is going to really save a lot of time for me! I'm also using Mandrill to send these, so i can check to make sure they were sent, and also i can see if the recipient opened the message..

  • Like 3
Link to comment
Share on other sites

i'm using PW pages for the email and i have contacts stored in pages and then i can use asmselect for choosing who to send to, 1 or more...

so for multiple i use the recipients array

Ok, if I got it right, you create a new page for a new message (regardless of single or bulk)

you select recipients via asm

create text, attach files, etc.

then at some point you need to save the page.

And now, - how do you execute the send? (scheduled or not)

Link to comment
Share on other sites

Right - and i have a cron job which runs every 5 min a 'mail_cron' template;

the template runs through some $pages->find and gets the messages to be sent;

I only use it to schedule emails (though if i needed to send it right away, i would set the send time for 5 min from now..)

this is the simple sending code:

https://gist.github.com/outflux3/797a18f5d2eaf0a87efb

but i'm working on changing over to this:

https://gist.github.com/outflux3/530b8adb1a6b7019d262

the only difference i added the table for sending multiple future-scheduled emails with the text placeholders;

so you could use the custom text placeholder to have an amount due and then in the message say "Amount Due by {{duedate}}: {{custom}}"

or you can just use the custom field to send slightly different messages for each instance..

Link to comment
Share on other sites

  • SebastianP changed the title to Strange PHP error in WireMailSmtp: unexpected fully qualified name "\getmessage"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...