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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Contact form - send mail not working...


Go to End


7 Posts   5634 Views

Avatar
Dan-Tom

Community Member, 7 Posts

14 July 2010 at 6:00am

Edited: 14/07/2010 6:01am

Hi, good jobs for SS!
BTW. I'm from Poland (Europa).. ;)

---

I add contact form with by http://www.ssbits.com/creating-a-simple-contact-form/

I add all source, send mail not working...
Pleas look for my official website: http://dan-tom.net , and look for this link: http://dan-tom.net/kontakt

When I send email in this page, contact form not send mail for my inbox (mail)...
Try it.

This is my ContactPage.php:

<?php

/* *****************

 * Model

 ******************/

class ContactPage extends Page

{

	static $db = array(

		'Mailto' => 'kontakt@dan-tom.net', //Email address to send submissions to

		'SubmitText' => 'HTMLText' //Text presented after submitting message

	);

	

	//CMS fields

	function getCMSFields() {

		$fields = parent::getCMSFields();

	

		$fields->addFieldToTab("Root.Content.OnSubmission", new TextField('Mailto', 'Email submissions to'));	

		$fields->addFieldToTab("Root.Content.OnSubmission", new HTMLEditorField('SubmitText', 'Text on Submission'));	

	

		return $fields;	

	}



}

/* *****************

 *  Controller

 ******************/

class ContactPage_Controller extends Page_Controller

{

	function ContactForm() {

      	// Create fields

		$Params = Director::urlParams();

		  

	    $fields = new FieldSet(

		    new TextField('Name', 'Name*'),

			new EmailField('Email', 'Email*'),

			new TextareaField('Comments','Comments*')

		);

	 	

	    // Create action

	    $actions = new FieldSet(

	    	new FormAction('SendContactForm', 'Send')

	    );

		// Create action

		$validator = new RequiredFields('Name', 'Email', 'Comments');

	

			

	    return new Form($this, 'ContactForm', $fields, $actions, $validator);

	}

 

	function SendContactForm($data) {

      

	 	//Set data

		$From = $data['Email'];

		$To = $this->Mailto;

		$Subject = "Website Contact message";  	  

		$email = new Email($From, $To, $Subject);

		//set template

		$email->setTemplate('ContactEmail');

		//populate template

		$email->populateTemplate($data);

		//send mail

		$email->send();

	  	//return to submitted message

		Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");



	}



	public function Success()

	{

		return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";

	}

}

Pleas, help me today. :)
greet, Dan-Tom.

Avatar
swaiba

Forum Moderator, 1899 Posts

14 July 2010 at 6:25am

Hi Dan-Tom,

Out of interest what does "not working" mean...

* email not being sent
* email sent but blank
* email sent but body is blank

I'd start by breaking this down, firstly I'd set the body as plain text "test" body to a hardcoded known email address.

$email = new Email('test@email.com', 'youremail@youremail.com', 'test subject','test body');
$email->send();

Then start adding items back in (like using the email from the contact form, then using the template, etc).
Hopefully it is something that can be found in that way and then worked around for now, e.g. If the template is not working then just create an email body with a built up string the old-fashioned way string.

Hope this helps you get an answer...

Barry

Avatar
Dan-Tom

Community Member, 7 Posts

14 July 2010 at 7:01am

Edited: 14/07/2010 7:15am

When I edit this?:

Out of interest what does "not working" mean...

* email not being sent
* email sent but blank
* email sent but body is blank

---

I add this code "$email = new Email('test@email.com', 'youremail@youremail.com', 'test subject','test body');" before "$email->send();"
Work, php module maito also so i need conf. this php source. :)

Avatar
swaiba

Forum Moderator, 1899 Posts

14 July 2010 at 7:07am

I'll take that to mean not sending, did you try overriding all the values like I suggested and it still did not work?

Avatar
Dan-Tom

Community Member, 7 Posts

14 July 2010 at 7:10am

I edit post, sorry.

Avatar
Dan-Tom

Community Member, 7 Posts

14 July 2010 at 7:58am

I apologize for double post.

I replace this:

//Set data

		$From = $data['Email'];

		$To = $this->Mailto;

To:

//Set data

		$From = $data['Email'];
		$To = "kontakt@dan-tom.net";

		$To -> $this;

Works perfectly!

Good? Blank page in /?success=1 is now...

Avatar
mhdesign

Community Member, 216 Posts

13 January 2012 at 1:15pm

After using this form successfully on a few sites I've struck a similar problem:

-- Form will submit in Mac OSX/Firefox but returns empty message to site administrator.
-- Form will not submit at all in Win/IE7

Don't know if this is down to it being Friday 13th or something more sinister... can anybody offer any useful suggestions?

thanks!