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.

Form Questions /

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

Testing email contact forms from local server


Go to End
Reply


3 Posts   200 Views

Avatar
racht

Community Member, 3 Posts

5 April 2017 at 9:56am

Edited: 05/04/2017 9:58am

Hi there,

I am building a contact form which sends an email upon submission using a combination of approaches provided in SilverStripe documentation (Introduction to frontend forms, and Simple contact form).

The code (included below) seems to be working fine, however I am wondering if it is possible to send test emails from a local server (in my case, MAMP) to properly test the functionality.

Many thanks in advance,
racht

public function ContactForm() {
			$form = Form::create(
				$this,
				__FUNCTION__,
				FieldList::create(
					TextField::create('Name','')
						->setAttribute('placeholder','Name*')
						->addExtraClass('form-field'),
					EmailField::create('Email','')
						->setAttribute('placeholder','Email*')
						->addExtraClass('form-field'),
					TextareaField::create('Message','')
						->setAttribute('placeholder','Message*')
						->addExtraClass('form-field')
				),
				FieldList::create(
					FormAction::create('submit', 'Send Message')
						->setUseButtonTag(true)
						->addExtraClass('text-button')
				),
				RequiredFields::create('Name','Email','Message')			
			);

			$form->addExtraClass('contact-form');

			return $form;
		}


		public function submit($data, $form){
			$email = new Email();

			$email->setTo('email@email.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();

			$form->sessionMessage("Thanks for your message, I'll get back to you as soon as I can",'good');

			return $this->redirectBack();
		}

Avatar
racht

Community Member, 3 Posts

8 April 2017 at 3:06pm

Edited: 08/04/2017 3:08pm

As per have updated the sendmail fields in the php.ini files in MAMP (both in MAMP/bin/php/php5.6.10/conf and MAMP/conf/php5.6.10) to:

 ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =/usr/sbin/sendmail -t -i -f  ryanachten@gmail.com 

As per, have updated the mysite/_config/config.yml to include:

Email:
  send_all_emails_to: 'ryanachten@gmail.com' 

All to no avail...does anyone have any suggestions how this might be resolved?

Avatar
iloveyou123

Community Member, 1 Post

29 April 2017 at 6:59pm

thanks for share