Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine 'Content-type' email header in order to send using HTML snippets #7

Closed
chrisbalt opened this issue Dec 30, 2014 · 5 comments
Closed

Comments

@chrisbalt
Copy link

Currently, if a user (dev) selects a snippet that contains HTML (such as your example sendform-table.php snippet, the HTML will deliver as text and render as such. As far as I can see, the only way to override this is to redefine the Content-Type property currently defined in the email class within the Kirby toolkit. Alternatively, a duplicate service adopter could be created with this one line changed, but that does not seem desirable.

Is there a way for SendForm.php to force the definition of this header to change?

@mzur
Copy link
Owner

mzur commented Jan 3, 2015

I think there is no way for this plugin to force a change of the header without using a new email service. A simple change of the default mail service would make this possible:

email::$services['html-mail'] = function($email) {
   $headers = array(
      'From: ' . $email->from,
      'Reply-To: ' . $email->replyTo,
      'Return-Path: ' . $email->replyTo,
      'Message-ID: <' . time() . '-' . $email->from . '>',
      'X-Mailer: PHP v' . phpversion(),
      // changed:
      'Content-Type: text/html; charset=utf-8',
      'Content-Transfer-Encoding: 8bit',
   );
   ini_set('sendmail_from', $email->from);
   $send = mail($email->to, str::utf8($email->subject), str::utf8($email->body), implode(PHP_EOL, $headers));
   ini_restore('sendmail_from');
   if(!$send) {
      throw new Error('The email could not be sent');
   }
};

The contact form plugin then would need a new option to set the email service manually.

@chrisbalt would you be happy with this solution? You could make this work right now if you added the above email service and called it mail, thus overwriting the default service.

@chrisbalt
Copy link
Author

@mzur I think you're right, it seems that either modifying the existing service–or adding a new service adopter–with the Content-Type properly set is the only way to go. Could instrument a somewhat-elegant solution if a new mail service could be defined outside of the Kirby toolkit. Could then detect some string (like "html") in the snippet filename, which would trigger use of the html-mail service. Until then, this works just fine.

Thanks for the response.

@mzur
Copy link
Owner

mzur commented Jan 5, 2015

An option to choose a (custom) email service will be added in v1.3 (#11).

@xu-chris
Copy link
Contributor

👍 @mzur You should add this to the plugin and/or to the README.md!

@mzur
Copy link
Owner

mzur commented Dec 29, 2015

I think it's rather for the Toolkit to implement this and allow different content types with the mail service or provide a new html-mail service. Feel free to request this feature 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants