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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Email doesnt send when I pass data in?

Go to End

5 Posts   1780 Views


Community Member, 46 Posts

29 November 2009 at 10:28pm


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>


Community Member, 607 Posts

1 December 2009 at 12:15am

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.



Community Member, 46 Posts

1 December 2009 at 9:34am

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.


Community Member, 607 Posts

1 December 2009 at 10:07am

Edited: 01/12/2009 10:09am

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.



Forum Moderator, 435 Posts

29 January 2010 at 1:58am

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?