Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Sending multipart mails?


Go to End


3 Posts   978 Views

Avatar
danzzz

Community Member, 175 Posts

5 May 2011 at 6:21am

Edited: 05/05/2011 6:25am

hi,

with

$themail->send();

I can send HTML mails, with

$themail->sendPlain();

textmails. But how to send multipart mails? I want to add plaintext part aswell the html part.
For example, if some mail clients dont allow htmls mails they only show plain text part of the mail.
With php.pear's mailer class for example I can attach 2 templates ...

And I have problems with (setTemplate) when using "sendPlain" (It sends only whats in $body variable).
Isnt it possible to use a template when using sendPlain()?

Avatar
swaiba

Forum Moderator, 1899 Posts

5 May 2011 at 6:49am

good question...

I do this...

$email->plaintext_body = strip_tags($email->body);

...I am very interested in other answer though...

Avatar
danzzz

Community Member, 175 Posts

5 May 2011 at 6:57am

hi

yes, I did it also a such way:

first I generate an array with template data, then I transform the array to an object and then render it with
the text part and html part. and then I also use the $plaintext_body var to add the plaintext template.

it works like that for me

$template_data = array(
			'ActivationLink' => Director::absoluteURL(Controller::join_links ('a',$this->Member->ID,"/{$this->Member->validationkey}")),
			'Personalisation' => 'Ser Anton',
		    );

		    $arrayData = new ArrayData($template_data);
		    $htmltemplate = $arrayData->renderWith('ReActivationMail');
		    $texttemplate = $arrayData->renderWith('ReActivationMailText');

		    $reactivationmail = new Email(
			$from = 'Sender <service@sender.com>',
			$to = $data['Email'],
			$subject = 'Sender Aktivierungsmail',
			$body = $htmltemplate,
			$plaintext_body = $texttemplate
		    );

		    $reactivationmail->send();