Please note that the forum isn't realy used anymore.

If you have questions, want support or just simply want to talk to us you can find us on slack.

 

Mail form to site owner and to mailinput in form + trigger event

In the code underneath you find the validation of a form. with $this->get('mailer')->addEmail('Nieuwe bestelling Van Vijle Uitvaartzorg', FRONTENDMODULESPATH . '/Projects/Layout/Templates/Mails/Order.tpl', array('order'=>$order, 'product'=>$product)); i mail to the owner of the site. ( mail with subject, content into template order.tpl ). I would also like to mail this form to the person who filled in the form ( $order['email'] = $this->frm->getField('email')->getValue(); ).

What is the best way to do this ?

I also would like to show a msg of confirmation after the form is send. What should my trigger event be for this?

Thx

Full code of the form:

/**
 * Validate the form
 */
private function validateForm()
{
    // is the form submitted
    if ($this->frm->isSubmitted())
    {
        // cleanup the submitted fields, ignore fields that were added by hackers
        $this->frm->cleanupFields();

        // validate required fields
        $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
        $this->frm->getField('fname')->isFilled(FL::err('MessageIsRequired'));
        $this->frm->getField('lint')->isFilled(FL::err('MessageIsRequired'));

        // correct?
        if ($this->frm->isCorrect())
        {
            // build array
            $order['email'] = $this->frm->getField('email')->getValue();
            $order['person'] = $this->frm->getField('person')->getValue();

            // add the email

              $this->get('mailer')->addEmail('Nieuwe bestelling Van Vijle Uitvaartzorg', FRONTEND_MODULES_PATH . '/Projects/Layout/Templates/Mails/Order.tpl', array('order'=>$order, 'product'=>$product));

            // trigger event



        }
    }
}

The thing is, that site is still running on 3.8.x so swiftmailer was not implemented yet. Is there anyway of doing is through the old(spoon?) mail methode?

You can just add two $this->get('mailer')->addEmail() statements?

i tried that , but it keeps on sending to the emailadres defined in the options of fork cms. I dont know how to add a custom emailadres ... forgive me my ignorance ( frontend design speaking here :) )

The function signature of the addEmail method is this:

public function addEmail(
    $subject,
    $template,
    array $variables = null,
    $toEmail = null,
    $toName = null,
    $fromEmail = null,
    $fromName = null,
    $replyToEmail = null,
    $replyToName = null,
    $queue = false,
    $sendOn = null,
    $isRawHTML = false,
    $plainText = null,
    array $attachments = null,
    $addUTM = false
) { }

This means that the fourth parameter of the function is the emailadres to send the email to, and the fifth parameter is the name of the person you're sending to.

You're a genious :) I couldnt find the function because i didnt know it which file it was.

I added :

              $this->get('mailer')->addEmail('Uw bestelling bij Van Vijle Uitvaartzorg', FRONTEND_MODULES_PATH . '/Projects/Layout/Templates/Mails/Order-klant.tpl', array('order'=>$order, 'product'=>$product), $order['email'], $order['fname'].' '.$order['fname'], 'info@vanvijle.be', 'Van Vijle Uitvaarzorg', 'info@vanvijle.be', 'Van Vijle Uitvaartzorg');

And it works like a charm! Thanks a lot, Wouter.

Comment

The forum is deprecated in favor of our Slack channel, which provides real-time support for your issues.

Join us on Slack here: https://fork-cms.herokuapp.com/