Login | Forgot password | Register
What is OpenID?
OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.
With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.
For more information visit the official OpenID site.
Form Questions
SilverStripe Forums » Form Questions » Custom contact form sending empty email
|
Page:
1
|
Go to End | |
| Author | Topic: Custom contact form sending empty email | 1256 Views |
-
Custom contact form sending empty email

2 April 2009 at 1:15am
Hi all,
I've got a custom email form that's sending empty emails. I'm guessing I'm not setting the template correctly - would appreciate some help with this. The template is located under the /email/ folder under mytheme/templates.
function doSubmit($postedData, $form) {
$subject = "Website Enquiry: ".$postedData["Subject"];
$email = new Email();
$email->setSubject($subject);
$email->ss_template = "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();
} -
Re: Custom contact form sending empty email

6 April 2009 at 11:43am
Hi guys,
Any ideas on this??
My email is still sending empty
-
Re: Custom contact form sending empty email

6 April 2009 at 12:00pm
Try this, change:
$email->ss_template = "ContactPageEmail";
to
$email->setTemplate('ContactPageEmail');and if that doesn't work put the template in /mysite/templates/
Hope that helps!
-
Re: Custom contact form sending empty email

27 April 2009 at 3:16am Last edited: 27 April 2009 3:17am
Hi guys
has anyone found a solution to this yet? I can't get the templates to work in any way, I just get an empty email.
Has anyone got email templates working in 2.3X? I'm trying to write a tutorial on creating a contact form but without templates it makes it pretty crude.
?
-
Re: Custom contact form sending empty email

27 April 2009 at 6:14pm
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.phpYou'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
-
Re: Custom contact form sending empty email

4 May 2009 at 4:30am
Thanks Pete
I descovered that the template has to be in themes/yourtheme/templates for the email to work.
Anyway all is fine now, you can see the tutorial here: http://www.ssbits.com/creating-a-simple-contact-form/
| 1256 Views | ||
|
Page:
1
|
Go to Top |
Currently Online: motly, jondbaker, tf22raptor
Welcome to our latest member: fearofbuttons




