Hi I'm having a problem sending emails. I have tried the email plugin and placing a function into the code section of the editor, but I still do not receive any emails. I can send a test message from the settings/Mail Templates area and this comes through fine.
I have the following code as the email function :
function onSend()
{
// Collect input
$name = post('name');
$email = post('email');
$subject = post('subject');
$body = post('body');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email,
'subject' => $subject,
'body' => $body,
],
[
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'body' => 'required',
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email','subject','body');
Mail::sendTo($to, 'nealh.website::mail.contactform', $params);
return true;
}
And this code for the form:
<form class="form-horizontal"id="form" name="contact-form" data-request="onSend()" data-request-success="alert('Message Sent')">
<div class="row">
<div class="col-md-6 no-padding">
<div class="col-md-12 required">
<input type="text" class="subfont" value="" name="name" placeholder="Enter name" required>
</div>
<div class="col-md-12 required">
<input type="email" class="subfont" value="" name="email" placeholder="Enter Email" required>
</div>
<div class="col-md-12 required">
<input type="text" class="subfont" value="" name="subject" placeholder="Enter Subject" required>
</div>
</div>
<div class="col-md-6 col-xs-12 required">
<textarea class="form-control subfont" value="" name="body" placeholder="Enter Message" cols="40" required></textarea>
</div>
</div>
<div class="row">
<div class="col-md-12 col-xs-12">
<button type="submit" class="btn dark pull-right">Send</button?
</div>
</div>
</form>
I'm new to October CMS so not sure if I am missing something simple.
Any help appreciated. Thanks NealH
Last updated