Jump to:

23473 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » My form cant send email

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

Page: 1
Go to End
Author Topic: 1603 Views
  • patjnr
    Avatar
    Community Member
    101 Posts

    My form cant send email Link to this post

    i have the following function in my page.php. its appears on every page as a quick contact form.
    the problem is that it can populate the database but its not sending me the data thru email.

    function submitContact($data, $form) {
        $submission = new ContactFormSubmission();
        $form->saveInto($submission);
       
        $email = new Email($data->Email, "name@yourdomain.com", "Quick contact from website", $data->Message);
    $email->send();
       
        $submission->write();   
    Session::set('Contacted', true);
    Director::redirectBack();
    }

  • PGiessler
    Avatar
    Community Member
    47 Posts

    Re: My form cant send email Link to this post

    Have you already checked to send a simple e-mail? Example: $email = new Email ( return adress, your adress, subject, body).
    I think that SilverStripe can't create the $body. Furthermore you can check this with Debug::Dump().

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: My form cant send email Link to this post

    thanks PGiessler
    if my statement is like this as you said it, it works
    $email = new Email ( from@yourdomain.com , to@yourdomain.com, subject, body).
    but the moment i try to populate the $data it wont send emails to me.
    now ca you help me get this $data populated.

    thank you

  • PGiessler
    Avatar
    Community Member
    47 Posts

    Re: My form cant send email Link to this post

    Hello patty,
    I corrected your source code, now you're able to send the email. You declare $data as an Object but it's an array.
    This was the only mistake! If my solution doesn't work, please write it down so I can look over the source code again.

    Best regards

    Pascal

    //modified SubmitContact

    function submitContact($data, $form) {
    $submission = new ContactFormSubmission();
    $form->saveInto($submission);
    $submission->write();

    $email = new Email($data['Email'], "name@yourdomain.com", "Quick contact from website", $data['Message']);
    $email->send();

    Session::set('Contacted', true);
    Director::redirectBack();
    }

    1603 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.