#1 2016-02-11 18:08:26

frkosk
Member
From: Slovakia
Registered: 2012-04-19
Posts: 20

[SOLVED] Send an email where admin's address depends on the select box

Hi, please advise me how to send email to admin, where the email address is not from site setting but from the selectbox in form.

Thank you very much

Offline

#2 2016-02-13 15:22:05

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: [SOLVED] Send an email where admin's address depends on the select box

Hi,

Form email is set within this file ..\application\libraries\MY_Email.php
Your see a switch

			switch($email)
			{
				case 'site':
					$email = (Settings::get('site_email') != '') ? Settings::get('site_email') : NULL;
					break;

				case 'form':
					$email = isset($data['email']) ? $data['email'] : self::$ci->input->post('email');
					break;

				case ($email == 'contact' || $email == 'technical' || $email == 'info'):
					$email = (Settings::get('email_'.$email) != '') ? Settings::get('email_'.$email) : NULL;
					break;

				default:
					$email = $email;
					$_email = explode('::', $email);
					if( ! empty($_email[1]) )
						$email = self::$ci->input->post($_email[1]);
					break;
			}

You could add another case that now checks for your selectbox selection:

case $email == 'selectbox':
	//here use the logic to grab data from your selectbox
	$email = isset($data['email']) ? $data['email'] : self::$ci->input->post('myselectbox');
	break;

Then use the 'selectbox' parameter within your form config:

        // Emails which will be send when the form is properly processed
        'emails' => array
        (
            // To Admin Email
            array
            (
                // Values can be :
                // - One plain Email address : my.name@mydomain.com
                // - 'form' to send it to the email of the form data
                // - 'site' to send it to the Email set in Ionize under Settings > Advanced > Email > Website
                // - 'contact' to send it to the Email set in Ionize under Settings > Advanced > Email > Contact
                // - 'info' to send it to the Email set in Ionize under Settings > Advanced > Email > Info
                // - 'technical' to send it to the Email set in Ionize under Settings > Advanced > Email > Technical
                // -  [b]selectbox parameter added here [/b]
                'email' => 'selectbox',
                // Email used for the reply_to Email
                'reply_to' => 'form',
                // Language term index, as set in language/xx/form_lang.php
                'subject' => 'mail_website_registration_subject',
                // View file to use for the email
                'view' => 'mail/register/to_admin',
            ),
            // To User Email
            array
            (
                'email' => 'form',
                'subject' => 'mail_user_registration_subject',
                'view' => 'mail/register/to_user',
            ),
        ),

Also you can find more information on how email processing works here http://doc.ionizecms.com/en/tags-reference/form-tags scroll further down.

Hope that helps.

Last edited by otemu (2016-02-13 15:22:19)

Offline

#3 2016-02-13 16:36:41

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: [SOLVED] Send an email where admin's address depends on the select box

Just to add if you don't need any custom logic, use the 'form' parameter which is already provided in the Class
..\application\libraries\MY_Email.php

case 'form':
    $email = isset($data['email']) ? $data['email'] : self::$ci->input->post('email');
    break;

Which automatically looks for the input containing email
This way you don't need to add any custom logic like I did above

in form config add

        // Emails which will be send when the form is properly processed
        'emails' => array
        (
            // To Admin Email
            array
            (
                // Values can be :
                // - One plain Email address : my.name@mydomain.com
                // - 'form' to send it to the email of the form data
                // - 'site' to send it to the Email set in Ionize under Settings > Advanced > Email > Website
                // - 'contact' to send it to the Email set in Ionize under Settings > Advanced > Email > Contact
                // - 'info' to send it to the Email set in Ionize under Settings > Advanced > Email > Info
                // - 'technical' to send it to the Email set in Ionize under Settings > Advanced > Email > Technical
                // -  [b]selectbox parameter added here [/b]
                'email' => 'form',

Make sure you name the input for your selectbox as email.

Hope that helps

Offline

#4 2016-02-15 15:51:09

frkosk
Member
From: Slovakia
Registered: 2012-04-19
Posts: 20

Re: [SOLVED] Send an email where admin's address depends on the select box

Hi otemu, thanks for the advice. I use the first method and modify the MY_Email library. In the form I have also email field for the user and the selectbox.

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations