This kind of works for me:
I put the following method in my Page_Controller:
function SendEmail($request) {
$subject = "Website Enquiry: ".$request["Subject"];
$email = new Email();
$email->setSubject($subject);
$email->setTemplate("ContactPageEmail");
$email->setFrom('noreply@mydomain.com');
$email->setTo('to@mydomain.com');
//$email->populateTemplate($postedData);
$email->send();
$form->sessionMessage('Thanks for contacting us. We\'ll get in touch with you as soon as possible!');
Director::redirectBack();
}
Then I put the following template code in mysite/templates/ContactPageEmail.ss:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2>$Subject</h2>
</body>
</html>
And if I go to url http://localhost/silverstripe/home/sendemail it blows up at the actual sending (as I don't have mail setup correctly) but it does create the template correctly as I checked both in Eclipse debugger and as you can see from the trace output on the page:
mail(to@mydomain.com,Website Enquiry: , This is a multi-part message in MIME format. ------=_NextPart_1393414 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Insert title here Website Enquiry: ------=_NextPart_1393414 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><!-- template D:/wamp/www/silverstripe/mysite/templates/ContactPageEmail.ss --> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DISO-8859-1"> <title>Insert title here</title> </head> <body> =09<h2>Website Enquiry: </h2> </body> </html><!-- end template D:/wamp/www/silverstripe/mysite/templates/ContactPageEmail.ss --> ------=_NextPart_1393414--,MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_1393414" Content-Transfer-Encoding: 7bit From: noreply@mydomain.com X-Mailer: SilverStripe Mailer - version 2006.06.21 (Sent from "localhost") X-Priority: 3 X-SilverStripeBounceURL: localhost/SilverStripe/Email_BounceHandler X-SilverStripeSite: mysite )
Line 157 of Mailer.php
You'll note that I didn't yet call populateTemplate() on the email. If I get time I'll see if I can put together a full working version today.
Pete