horst

WireMailSmtp

Recommended Posts

opalepatrick    19

OK thanks Horst. I did start to use it this way, but was unsure about the other aspects and if more was included. I don't have a problem with the validation/sanitising routines per se. So thank you.

  • Like 1

Share this post


Link to post
Share on other sites
alan    364

Horst, please can you tell me where the changelog for 0.2.2 is (I checked the usual spots), or am I safe to assume any _ . _ . N level change is so minor I can always just install it without any other checking on my sites etc? Thank you ^_^

Share this post


Link to post
Share on other sites
mr-fan    806

Using WireSmtp for WireMail so far...so great...my question is more based on the basic WireMail thing i think but i'm not shure:

using this call:

$mail = wireMail();
$mail->to($u->email);
$subject = '=?UTF-8?B?'.base64_encode('ÖÄÜ ö ä ü ß').'?=';
$mail->subject($subject);
$mail->bodyHTML($emailContentHtml);
$mail->send();

i don't get german umlaute öäüß working in the subject??

I've read the forum and stackoverflow but this is the only solution everyone points out so i'm a little lost...how to debug or get it work.

Best regards mr-fan

Share this post


Link to post
Share on other sites
horst    3,962

You don't need anything like this. Just make sure that your php files are really stored in utf-8 encoding!! (PHP files you need to check in this reagrd are: the calling template file(s), the WireMailSMTP module files and the base WireMail files) Normally they all should be in utf-8 encoding, but better you check this thouroughly.

Then it works with simply using:

$subject = 'Ö Ä Ü ö ä ü ß';

I tested this just yet. The source of the received email looks like:

Subject: Wiremail-SMTP Test 15:57:23 =?UTF-8?q?=C3=A4=C3=B6=C3=BC_=C3=84=C3=96=C3=9C_=C3=9F?=
X-Mailer: ProcessWire/WireMailSmtp
Date: Wed, 8 Jun 2016 13:57:25 GMT +00:00
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

It does automated encoding, but you don't have to do anything by yourself.

  • Like 2

Share this post


Link to post
Share on other sites
mr-fan    806

Thank you very much - has a wrong encoding on my PHP Editor setup....so you saved my day!

Best regards mr-fan

Share this post


Link to post
Share on other sites
titanium    61

Horst did a nice job building this module.

One thing I'm missing though: Is there a method to embed an image? (cid-method). I've searched through the documentation of Manuel Lemos classes and found the following:

Quote

 

Alternatively, an image file can be embedded in an HTML message using multipart/related message parts. This type of message part is composed by creating the image file part with the CreateFilePart function.

Then use the GetPartContentID function the image part identifier text. Prepend the string 'cid:' to this identifier to form a special URL that should be used in the HTML part to reference the image part like this:

$image_tag = '<img src="cid:' . $message_object->GetPartContentID($image_part) . '">';

When you have composed the whole HTML document, create the HTML message part with the CreateHTMLPart or the CreateQuotedPrintableHTMLPart functions, and finally use the CreateRelatedMultipart function to create a message part that can be added to the message with the function AddAlternativeMultipart like HTML messages with alternative text parts described before.

Note that the HTML part must be the first listed in the parts array argument that is passed to the function CreateRelatedMultipart, or else the message may not appear correctly.

Note also that when you are composing an HTML message with embedded images and an alternative text part, first you need to create the multipart/alternative part with the HTML and the text parts using the CreateAlternativeMultipart function, and then you add the multipart/related part to the message with the AddRelatedMultipart function, passing an array of parts that lists first the multipart/alternative part and then the image part created before.

 

Seems the classes support embedding, but I guess the module does not yet?

Share this post


Link to post
Share on other sites
horst    3,962

No, the module doesn't support it. And I cannot see much benefit for it. This is the only part what would be a really pain in the ***, if one would try to integrate this. And AFAIK, you get the same effect if you use the base64 data with your img src. And this can be done outside of the module.

 

// when building your HTML-content, you simply can add something like

$htmlcontent .= "<img src='data:image/png;base64," . base64_encode(file_get_contents($image->width(300)->filename)) . "' />";

 

Edited by horst
added code example
  • Like 1

Share this post


Link to post
Share on other sites
mrkhan    10

Hello,

I am building one form to send email with WireMailSmtp

every thing is working fine, only thing attachments are sending with email without any extension.

what i want to do is
Send email with attachment, this script send attachment with email but files are names like bnvft & angth (random names without extensions).
 

here is my code

if (isset($input->post->submit)) {

$form = array(
'name' => $input->post->name,
'email' => $input->post->email,
'message' => $input->post->message,
'email2' => $input->post->email2
);

$photo=$filetemp = $_FILES["photo"];
/// how to check that file is only image

$resume=$filetemp = $_FILES["resume"];
/// how to check the file is only PDF or word file

/// email12 is for spam boot
if($form[email2] =="")
{
$toName='my website';
$toEmail=$page->email;
$subject="CV EMail";
$textBody= "Full name: $form[name]\n" .
               "Email: $form[email]\n" .
			   "Message: $form[message]";

$mail = wireMail();
$mail->to($toEmail, $toName);
$mail->from = $toEmail; 
$mail->subject($subject);

$mail->attachment($photo);
$mail->attachment($resume);

$mail->body($textBody);

$numSent = $mail->send();
if($numSent)
{
  $output="Message Send";
}else{
  $output="Message Not Send";
}

}

}

Share this post


Link to post
Share on other sites
horst    3,962

From where do you get the file(s)?

Can you please show this exact code snippet? (and only this, please) :)

The module is working fine. It just uses what you passes to it. So, you probably do something wrong in regard of your filenames / files passing to the module.

Share this post


Link to post
Share on other sites
mrkhan    10

Hello @horst,

Thanks for quick response, i am getting files from form , bellow is my form code

<form id="contactForm" action="" method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
 <input type='text' name='name' id='name' required="" value='' maxlength="50" /><br/>
<input type='email' name='email' id='email' required="" value='' maxlength="50" /><br/>
<input type="file" name='photo' id='photo' accept='image/jpg,image/jpeg,image/gif,image/png' /><br/>
<input type="file" name='resume' required="" id='resume' accept="application/pdf,application/msword" /><br/>
</form>

and my php code is as i post above
 

$photo=$_FILES["photo"];
$resume=$_FILES["resume"];

$mail = wireMail();
$mail->to($toEmail, $toName);
$mail->from = $toEmail; 
$mail->subject($subject);

/// these are attachemnts
$mail->attachment($photo);
$mail->attachment($resume);

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

But when i got email i got two attachments with random names but no extension.

Thanks

 

Share this post


Link to post
Share on other sites
horst    3,962

Yes you get random names because you assigned them to your variables. If you don't like them, don't assign them. :)

$photo=$filetemp = $_FILES["photo"]["tmp_name"];

This has nothing to do with my module nor with PW. I suggest to follow up with the php docs on how to upload files, followed by how to use it with PWs WireUpload class. There you also have validation options for filetypes. IMO this is essential knowledge in regard of security to your website. Open it for uploads must be done in a secure way. Therefore you must understand, at least to a small extend, what you are doing.

  • Like 1

Share this post


Link to post
Share on other sites
mrkhan    10
3 minutes ago, horst said:

Yes you get random names because you assigned them to your variables. If you don't like them, don't assign them. :)

$photo=$filetemp = $_FILES["photo"]["tmp_name"];

This has nothing to do with my module nor with PW. I suggest to follow up with the php docs on how to upload files, followed by how to use it with PWs WireUpload class. There you also have validation options for filetypes.

even i use bellow i code i am getting same random names with no extension, why extensions are missing ?
 

$photo=$_FILES["photo"];
$resume=$_FILES["resume"];

Share this post


Link to post
Share on other sites
netcarver    1,881

@mrkhan You are not handling the uploads correctly at the moment, take a close look at the first comment on the page horst pointed you to. It shows you what you need to know about handling file uploads. You should not trust the file-name supplied by the upload so that example shows you how to

  • validate that the file was supplied via an upload (using the move_uploaded_file() function)
  • how to name it without having to trust the supplied file name
  • how to validate the mime type of the file
  • how to append the extension that represents the file type of the uploaded file

You just need to remember the name you gave it when you moved it and attach that to your outgoing email. I've updated part of the code from the comment I linked to so that you can see how you might generate the new name and extension.

    // You should name it uniquely.
    // DO NOT USE $_FILES['upfile']['name'] WITHOUT ANY VALIDATION !!
    // On this example, obtain safe unique name from its binary data.
    $new_name = "./uploads/" . sha1_file($_FILES['upfile']['tmp_name'] . ".$ext";
    if (!move_uploaded_file($_FILES['upfile']['tmp_name'], $new_name))) {
        throw new RuntimeException('Failed to move uploaded file.');
    }

    // Now attach the uploaded, validated & renamed file to your email.
    $mail->attachment($new_name);

You'll need to tailor the code to do the needed validation on both of the files you want your users to upload of course. Don't forget to change where you want the files copied to as well.

  • Like 6

Share this post


Link to post
Share on other sites
Ivan Gretsky    804

Good day!
Is it somehow possible to test sending emails with WireMailSMTP without them actually being send? Something like you can do with regular php mail function in xampp where all the mail is put into a folder.

Share this post


Link to post
Share on other sites
horst    3,962

Hi, no, it isn't possible currently out of the box.

You can hook into the ___send() method, and add / change the line 705, where the message normally will be send. Don't know if this is an easy task, as the method is really huge. I find this useful too, and add it to the feature request list of the module, but don't expect an early release.

  • Like 2

Share this post


Link to post
Share on other sites
LostKobrakai    4,313

I've just created a custom WireMail module, which does currently plainly logs all method calls and it's parameters to a logfile. I simply installed that one locally and WireMailSmtp on the live site.

  • Like 3

Share this post


Link to post
Share on other sites
Ivan Gretsky    804
14 minutes ago, LostKobrakai said:

I've just created a custom WireMail module, which does currently plainly logs all method calls and it's parameters to a logfile. I simply installed that one locally and WireMailSmtp on the live site.

Can you share it?

  • Like 2

Share this post


Link to post
Share on other sites
szabesz    1,389
10 minutes ago, LostKobrakai said:

It could certainly be improved, but here you go. I'll probably not going to release it officially, so if someone would like to take a shot at it, feel free.

WireMailTesting.zip

Thank you very much!

Share this post


Link to post
Share on other sites

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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By antoiba86
      I am a bit confused, because I don't know how to solve this problem.
      When I install the module Languages Support - Page Names, my web falls apart.
      I have all the necessary modules installed as Language support for example.
      This is the error I get in the admin panel.
      Warning: Invalid argument supplied for foreach() in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 107 Warning: Invalid argument supplied for foreach() in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 198 Warning: Invalid argument supplied for foreach() in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 1011 Warning: Invalid argument supplied for foreach() in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 1011 Warning: Invalid argument supplied for foreach() in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 1041
      And this in the front-end.
      Warning: Invalid argument supplied for foreach() in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 107
      Fatal error: Call to a member function get() on null in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 605 Fatal error: Call to a member function get() on null in /hosting/www/antoibaprogramming.com/public/wire/modules/LanguageSupport/LanguageSupportPageNames.module on line 605
    • By kongondo
      The Module Blog for ProcessWire replicates and extends the popular Blog Profile.
      Blog is now in version 2.
      Please read the README in the Github link below in its entirety before using this module 
      Blog Documentation is here (Work in Progress!)
      See this post for new features in version 2 or the readme in GitHub.
      To upgrade from version 1, see these instructions.
      ##################################################
      Most of the text below refers to Blog version 1 (left here for posterity). 
       
      Blog version 1 consists of two modules:
      ProcessBlog: Manage Blog in the backend/Admin.
      MarkupBlog: Display Blog in the frontend.
      Being a module, Blog can be installed in both fresh and existing sites. Note, however, that presently, ProcessBlog is not compatible with existing installs of the Blog Profile. This is because of various structural and naming differences in respect of Fields, Templates, Template Files and Pages. If there is demand for such compatibility, I will code a separate version for managing Blog Profile installs.
      In order to use the 'Recent Tweets Widget', you will need to separately install and setup the module 'MarkupTwitterFeed'.
      Please read the README in the Github link below in its entirety before using this module (especially the bit about the Pages, etc. created by the module). 
      I'll appreciate Beta testers, thanks! Stable release works fine.
      Download
      Modules Directory: http://modules.processwire.com/modules/process-blog/
      Github: https://github.com/kongondo/Blog
      You can also install from right within your ProcessWire install.
      Screenshots (Blog version 1)

      Video Demos
      ProcessBlog
      MarkupBlog
      Credits
      Ryan Cramer
      The Alpha Testers and 'Critics' 
      License
      GPL2
    • By bernhard
      hi everybody,
      this is a preview of a module that i'm working on for quite a long time. I needed it for an intranet office management application that i'm still working on. It makes it very easy to create very customized Datatables using the awesome jquery datatables plugin (www.datatables.net)
       
      EARLY ALPHA release!
      It's very likely that there will lots of changes to this module that may cause breaking your implementations.
       
      Module source
      sorry, removed as it changes too frequently; closed alpha - contact me if you think you can contribute
       
       
      Remarks:
      The module is intended to be used on the backend. Loading styles is at the moment only done via adding files to the $config->styles/scripts arrays. Also the communicaton to javascript is done via the $config->js() method that is built into the admin and would have to be implemented manually on frontend use. But it would not be difficult of course
      Installation:
      Nothing special here, just download + install
       
      edit: removed some parts, because i made a complete rewrite of the module! (see last posting in the thread)
       
      Customization example:
      in the screencast you see an example that i'm using in a process module. i put the table inside an InputfieldMarkup just to have the same look&feel all around the admin. you see that you could also use this module to create tables quickly and easily using @kongondo s runtime markup module.
      complete PHP code:
      $this->headline('Kundenliste'); $form = $modules->get('InputfieldForm'); // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // type $col = new dtCol(); $col->name = 'type'; $col->data = function($page) { return $page->rockcontact_type->title; }; $dt2->cols->add($col); // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); $f = $modules->get('InputfieldMarkup'); $f->value = $dt2->render(); $form->add($f); // ################################## // ajax request -> return data // non-ajax -> render form + table // ################################## if($config->ajax) { echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else $out .= $form->render(); return $out; what is interesting here is this part:
      // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); datatables support orthogonal data (https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html). a date column is a good example, because you need to DISPLAY a formatted date (like 10.02.2017) but you need to be able to SORT this column by a different value (timestamp). its very easy to accomplish this by providing both values in your json. Btw: You could also just transfer the timestamp and do the formatting on the client-side via javascript. Next Example will show ho this would work. Both cases can be necessary, it's just an example here.
      [...] removed
      Why i created this module:
      of course i know @Soma s module but i needed a lot more features and the newer datatables version. also i like to define all the columns as objects and have everything on one place. lister & markupadmindatatable: nice for basic tables but lacks of features to modify the appearance of the cell values (like rendering icons, background colors and so on) datatables provides a great frontend API for filtering, showing/hiding columns, getting data, modifying it... it also plays well together with frontend charts like google chart api in this case:
       
      todo / roadmap:
      all kinds of column filters (like seen in the example above that shows an older and bloated version of this module) support for ajax filters and pagination (currently all filtering and sorting is done on the client side. i tried it with up to 50.000 rows and got reasonable results. initial loading took around 10sec. but of course this heavily depends on the complexity of your table and your data.  
       
       
    • By Robin S
      PageListTrash
      Allows non-superusers to trash pages directly from Page List (if they have page-delete permission for that page).
      Not much to say really - the module adds a "Trash" option to the extra actions for pages in Page List. It looks and works just like the Trash action available to superusers.

      https://github.com/Toutouwai/PageListTrash/
       
      Up to you whether you think non-superusers should be trusted with simpler trashing. For most cases I like the default behaviour where editors have to jump through some more hoops - I want them to think carefully about what they are doing. But if an editor needs to trash several pages then this module might reduce frustration.
      @tpr, by now you can probably predict what I'm going to say...
      ...something to merge into AdminOnSteroids?
    • By celfred
      Hello,
      I'm desperately trying to update my website to PW 3.0.62 and I'm facing issues to to module compatibility. I was stuck with Pages2Pdf which I managed to solve bu updating the module from Github, but now it's the Pages Web Service module... and this time, I don't know wht to do
      The Module is found there. But it is quite old and I can't find it in the modules catalogue... and my site is making quite a use of it (I can't think of a way to do otherwise, sorry...)
      After adding the FileCompiler=0 to the module pages, the error I'm stuck with is :
      Fatal error: Class 'WireData' not found in /home/celfred/PlanetAlert/site/modules/ServicePages/ServicePages.module on line 22
      and I have no idea on what to do... I must admit I'm not a programmer but a middle-school teacher... (for your information, here's the site I'm talking about : http://planetalert.tuxfamily.org ) but I'm struggling hard to solve the different issues I have to face and I'm wlling to understand things. I have just spent many hours trying to make 2.8 work on my localhost (and it seems ok ) but I'd like to switch to 3.x to prepare the future
      If anyone had the will to spend a few minutes to try and help me, I would greatly appreciate.
      Thanks in advance !
      If you need more information to understand my problem, feel free to ask.