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.

General Questions

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

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

Email doesnt send when I pass data in?


5 Posts   1420 Views


29 November 2009 at 10:28pm Community Member, 46 Posts


I am trying to send send an email in response to a form submission. The email will send until I populate the email template with the data. Does anybody know why this might be?

Here is my code...

function EnquireAction($data, $form) {

    $submission = new Enquiry();
   $Full_name = $data['First_name']." ".$data['Surname'];
   $Wine = $data['Wine_name'].", ".$data['Vintage'].", ".$data['Region'].", ".$data['Colour'];
   $email = new Email(**FROM EMAIL**, **SEND TO**, "New Wine List Enquiry");

            'FullName' => $Full_name,
            'Email' => $data['Email'],
            'Telephone' => $data['Telephone'],
            'Wine' => $Wine,
            'Price' => $data['price'],
            'Desc' => $data['Desc']

      Debug::show("Not sent");
//Director::redirectBack(Director::baseURL(). "/thank-you");

The template is...

Hi Ben,<br/><br/>
<p>You have had a new enquiry from the wine list.</p>
<p>From: $FullName</p>
<p>Email: $Email</p>
<p>Telephone: $Telephone</p>
<p>Wine: $Wine</p>";
<p>Price on website: &pound;$Price</p>
<p>User comments: $Desc</p>
The website</p>


1 December 2009 at 12:15am Community Member, 604 Posts

I had this exact problem a few weeks ago, but haven't had time to track down a specific bug, nor could I find on in Trac.

My fix for this was to use the Email classes setTo() and setFrom() methods to set the headers AFTER the data is passed.

I remember pumping the object on screen and seeing that the recipient field was blank if I didn't do that, even though it was present prior to the populateTemplate call.



1 December 2009 at 9:34am Community Member, 46 Posts

Thanks for the help Double-a-ron. I had a go at that. Didnt seem to work :-(

I tried to sendPlain instead and this works. Will do me for the moment.


1 December 2009 at 10:07am (Last edited: 1 December 2009 10:09am), Community Member, 604 Posts

Hi mate,

I just dug out the exact code I was having the same issue with.

// send an email to the customer
$to = $this->OrderEmail;
$subject = 'Order confirmation';
$e = new $emailClass($to, $adminEmail, $subject);
"Order" => $this,
"Member" => $member

// At this point, for some reason the subject and recipient go AWOL from the Object - Reset them!
if(isset($subject)) $e->setSubject($subject);


The code is taken from the Ecommerce module. I'm willing to bet that if you output your email object on screen when you do this send, you find that the "to" data is blank.



29 January 2010 at 1:58am Forum Moderator, 435 Posts

I wrote:

$templateData = array(
'WelcomeMessage' => $welcomeMsg, // Accessible in template via $WelcomeMessage
'VarFirstName' => $SignupFirst,
'VarEmail' => $SignupEmailAddress,
'VarPassword' => $SignupPwd,
'VarSurname' => $SignupSurn

and my template is:

      <h3>Hi, $VarFirstName $VarSurname.</h3>



but my template vars on are not populated. Only $WelcomeMessage. Why?