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.

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

My form cant send email


Go to End


4 Posts   2288 Views

Avatar
patjnr

Community Member, 102 Posts

11 May 2009 at 8:50pm

Edited: 11/05/2009 10:38pm

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();
}

Avatar
PGiessler

Community Member, 47 Posts

12 May 2009 at 7:28pm

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().

Avatar
patjnr

Community Member, 102 Posts

13 May 2009 at 9:53pm

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

Avatar
PGiessler

Community Member, 47 Posts

14 May 2009 at 7:28pm

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();
}