Jump to:

23376 Posts in 18218 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Simple Contact Form

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: 359 Views
  • Bagzli
    Avatar
    Community Member
    26 Posts

    Simple Contact Form Link to this post

    Hi Guys,

    I've been trying to send an e-mail out and followed the official guide however I am not receiving any e-mails. I cannot figure out what is wrong, here is my code:

    <?php
    class ContactPage extends Page {
    }
    class ContactPage_Controller extends Page_Controller {
    private static $allowed_actions = array('$Form');
    public function Form() {
    $fields = new FieldList(
    new TextField('Name'),
    new EmailField('Email'),
    new TextareaField('Message')
    );
    $actions = new FieldList(
    new FormAction('submit', 'Submit')
    );
    $validator = new RequiredFields('Name', 'Message');
    return new Form($this, '$Form', $fields, $actions, $validator);
    }
    public function submit($data, $form) {
    $email = new Email();

    $email->setTo('myemail@mymail.com');
    $email->setFrom($data['Email']);
    $email->setSubject("Contact Message from {$data["Name"]}");

    $messageBody = "
    <p><strong>Name:</strong> {$data['Name']}</p>
    <p><strong>Message:</strong> {$data['Message']}</p>
    ";
    $email->setBody($messageBody);
    $email->send();
    return array(
    'Content' => '<p>Thank you for your feedback.</p>',
    'Form' => ''
    );
    }
    }

    My ContactForm.ss looks like this

    $Form

    my Page.ss looks like this

    $Content
    $Form

    Note: I changed the e-mail displayed in the code above, but in my actual code I use my real e-mail.

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: Simple Contact Form Link to this post

    Does the from email address exist? This was a problem on some of my hosting envoronments.

  • Bagzli
    Avatar
    Community Member
    26 Posts

    Re: Simple Contact Form Link to this post

    yes it does, I've used 2 of my e-mails that I know exist.

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: Simple Contact Form Link to this post

    Hi,

    Does using a normal php mail function work?
    And did you try it on antoher webserver?

    Cheers,

    Bart

  • Bagzli
    Avatar
    Community Member
    26 Posts

    Re: Simple Contact Form Link to this post

    I was doing it from a local server and never tried normal one, not sure how the normal one is done.

  • kevinstripe
    Avatar
    Community Member
    10 Posts

    Re: Simple Contact Form Link to this post

    first you should try using simple PHP mail function, to check whether your SMTP server is working fine....

  • bartvanirsel
    Avatar
    Community Member
    94 Posts
    359 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.