0

I need to send an email notification to an specific address after channel form is submited.. The email address depend on the selection of a field in the form.. I know there's might be a hook for that but i don't know how to use it..

Thanks!

2 Answers 2

1

After many trial and error (as i'm not a real programmer).. i finally found something that works.. For all the newbies like me.. you need to have an addon.setup.php file and a ext.YOUR-THING.php as explain in the main doc https://docs.expressionengine.com/latest/development/addon_setup_php_file.html and https://docs.expressionengine.com/latest/development/extensions.html.. Then my main script inside my extension file..

function channel_form_submit_entry_end( $cf ) {

    ee()->load->library( 'email' );

    $var = ee()->input->post( 'YOUR-POST-INPUT-NAME', TRUE );
    if ( $var == '123' ) {
        $recipient = '[email protected]';
    } else {
        $recipient = '[email protected]';
    };


    ee()->load->library( 'email' );
    ee()->load->helper( 'text' );

    ee()->email->wordwrap = true;
    ee()->email->mailtype = 'text';
    ee()->email->from( '[email protected]' );
    ee()->email->to( $recipient );
    ee()->email->subject( 'YOUR SUBJECT' );
    ee()->email->message( entities_to_ascii( 'YOUR BODY MESSAGE' ) );
    ee()->email->Send();

}

I know it may not be the cleanest script by it works!.. If someone wish to clean this.. please feel free!

0

There is a hook. Find details here:

https://docs.expressionengine.com/latest/development/extension-hooks/module/channel-form.html#channel_form_submit_entry_endchannel_form_obj

All you have to do this is to create an extension file. Initialize email library. You can find fields data in 'parameter you passed in function' or in POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.