function swpsmtp_settings()
    {
        $display_add_options = $message = $error = $result = '';
        $swpsmtp_options = get_option('swpsmtp_options');
        if (isset($_POST['swpsmtp_form_submit']) && check_admin_referer(plugin_basename(__FILE__), 'swpsmtp_nonce_name')) {
            /* Update settings */
            $swpsmtp_options['from_name_field'] = isset($_POST['swpsmtp_from_name']) ? sanitize_text_field(wp_unslash($_POST['swpsmtp_from_name'])) : '';
            if (isset($_POST['swpsmtp_from_email'])) {
                if (is_email($_POST['swpsmtp_from_email'])) {
                    $swpsmtp_options['from_email_field'] = sanitize_email($_POST['swpsmtp_from_email']);
                } else {
                    $error .= " " . __("Please enter a valid email address in the 'FROM' field.", 'easy-wp-smtp');
                }
            }
            $swpsmtp_options['smtp_settings']['host'] = sanitize_text_field($_POST['swpsmtp_smtp_host']);
            $swpsmtp_options['smtp_settings']['type_encryption'] = isset($_POST['swpsmtp_smtp_type_encryption']) ? sanitize_text_field($_POST['swpsmtp_smtp_type_encryption']) : 'none';
            $swpsmtp_options['smtp_settings']['autentication'] = isset($_POST['swpsmtp_smtp_autentication']) ? sanitize_text_field($_POST['swpsmtp_smtp_autentication']) : 'yes';
            $swpsmtp_options['smtp_settings']['username'] = sanitize_text_field($_POST['swpsmtp_smtp_username']);
            $smtp_password = trim($_POST['swpsmtp_smtp_password']);
            $swpsmtp_options['smtp_settings']['password'] = base64_encode($smtp_password);
            /* Check value from "SMTP port" option */
            if (isset($_POST['swpsmtp_smtp_port'])) {
                if (empty($_POST['swpsmtp_smtp_port']) || 1 > intval($_POST['swpsmtp_smtp_port']) || !preg_match('/^\\d+$/', $_POST['swpsmtp_smtp_port'])) {
                    $swpsmtp_options['smtp_settings']['port'] = '25';
                    $error .= " " . __("Please enter a valid port in the 'SMTP Port' field.", 'easy-wp-smtp');
                } else {
                    $swpsmtp_options['smtp_settings']['port'] = sanitize_text_field($_POST['swpsmtp_smtp_port']);
                }
            }
            /* Update settings in the database */
            if (empty($error)) {
                update_option('swpsmtp_options', $swpsmtp_options);
                $message .= __("Settings saved.", 'easy-wp-smtp');
            } else {
                $error .= " " . __("Settings are not saved.", 'easy-wp-smtp');
            }
        }
        /* Send test letter */
        if (isset($_POST['swpsmtp_test_submit']) && check_admin_referer(plugin_basename(__FILE__), 'swpsmtp_nonce_name')) {
            if (isset($_POST['swpsmtp_to'])) {
                if (is_email($_POST['swpsmtp_to'])) {
                    $swpsmtp_to = $_POST['swpsmtp_to'];
                } else {
                    $error .= " " . __("Please enter a valid email address in the 'FROM' field.", 'easy-wp-smtp');
                }
            }
            $swpsmtp_subject = isset($_POST['swpsmtp_subject']) ? $_POST['swpsmtp_subject'] : '';
            $swpsmtp_message = isset($_POST['swpsmtp_message']) ? $_POST['swpsmtp_message'] : '';
            if (!empty($swpsmtp_to)) {
                $result = swpsmtp_test_mail($swpsmtp_to, $swpsmtp_subject, $swpsmtp_message);
            }
        }
        ?>
		<div class="swpsmtp-mail wrap" id="swpsmtp-mail">
			<div id="icon-options-general" class="icon32 icon32-bws"></div>
			<h2><?php 
        _e("Easy WP SMTP Settings", 'easy-wp-smtp');
        ?>
</h2>
                        <div class="update-nag">Please visit the <a target="_blank" href="https://wp-ecommerce.net/easy-wordpress-smtp-send-emails-from-your-wordpress-site-using-a-smtp-server-2197">Easy WP SMTP</a> documentation page for usage instructions.</div>
			<div class="updated fade" <?php 
        if (empty($message)) {
            echo "style=\"display:none\"";
        }
        ?>
>
				<p><strong><?php 
        echo $message;
        ?>
</strong></p>
			</div>
			<div class="error" <?php 
        if (empty($error)) {
            echo "style=\"display:none\"";
        }
        ?>
>
				<p><strong><?php 
        echo $error;
        ?>
</strong></p>
			</div>
			<div id="swpsmtp-settings-notice" class="updated fade" style="display:none">
				<p><strong><?php 
        _e("Notice:", 'easy-wp-smtp');
        ?>
</strong> <?php 
        _e("The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'easy-wp-smtp');
        ?>
</p>
			</div>
			<h3><?php 
        _e('General Settings', 'easy-wp-smtp');
        ?>
</h3>
			<form id="swpsmtp_settings_form" method="post" action="">					
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php 
        _e("From Email Address", 'easy-wp-smtp');
        ?>
</th>
						<td>
							<input type="text" name="swpsmtp_from_email" value="<?php 
        echo esc_attr($swpsmtp_options['from_email_field']);
        ?>
"/><br />
							<span class="swpsmtp_info"><?php 
        _e("This email address will be used in the 'From' field.", 'easy-wp-smtp');
        ?>
</span>
					</td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php 
        _e("From Name", 'easy-wp-smtp');
        ?>
</th>
						<td>
							<input type="text" name="swpsmtp_from_name" value="<?php 
        echo esc_attr($swpsmtp_options['from_name_field']);
        ?>
"/><br />
							<span  class="swpsmtp_info"><?php 
        _e("This text will be used in the 'FROM' field", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>			
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Host', 'easy-wp-smtp');
        ?>
</th>
						<td>
							<input type='text' name='swpsmtp_smtp_host' value='<?php 
        echo esc_attr($swpsmtp_options['smtp_settings']['host']);
        ?>
' /><br />
							<span class="swpsmtp_info"><?php 
        _e("Your mail server", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('Type of Encription', 'easy-wp-smtp');
        ?>
</th>
						<td>
							<label for="swpsmtp_smtp_type_encryption_1"><input type="radio" id="swpsmtp_smtp_type_encryption_1" name="swpsmtp_smtp_type_encryption" value='none' <?php 
        if ('none' == $swpsmtp_options['smtp_settings']['type_encryption']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('None', 'easy-wp-smtp');
        ?>
</label>
							<label for="swpsmtp_smtp_type_encryption_2"><input type="radio" id="swpsmtp_smtp_type_encryption_2" name="swpsmtp_smtp_type_encryption" value='ssl' <?php 
        if ('ssl' == $swpsmtp_options['smtp_settings']['type_encryption']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('SSL', 'easy-wp-smtp');
        ?>
</label>
							<label for="swpsmtp_smtp_type_encryption_3"><input type="radio" id="swpsmtp_smtp_type_encryption_3" name="swpsmtp_smtp_type_encryption" value='tls' <?php 
        if ('tls' == $swpsmtp_options['smtp_settings']['type_encryption']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('TLS', 'easy-wp-smtp');
        ?>
</label><br />
							<span class="swpsmtp_info"><?php 
        _e("For most servers SSL is the recommended option", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Port', 'easy-wp-smtp');
        ?>
</th>
						<td>
							<input type='text' name='swpsmtp_smtp_port' value='<?php 
        echo esc_attr($swpsmtp_options['smtp_settings']['port']);
        ?>
' /><br />
							<span class="swpsmtp_info"><?php 
        _e("The port to your mail server", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Authentication', 'easy-wp-smtp');
        ?>
</th>
						<td>
							<label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='no' <?php 
        if ('no' == $swpsmtp_options['smtp_settings']['autentication']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('No', 'easy-wp-smtp');
        ?>
</label>
							<label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='yes' <?php 
        if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('Yes', 'easy-wp-smtp');
        ?>
</label><br />
							<span class="swpsmtp_info"><?php 
        _e("This options should always be checked 'Yes'", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP username', 'easy-wp-smtp');
        ?>
</th>
						<td>
							<input type='text' name='swpsmtp_smtp_username' value='<?php 
        echo esc_attr($swpsmtp_options['smtp_settings']['username']);
        ?>
' /><br />
							<span class="swpsmtp_info"><?php 
        _e("The username to login to your mail server", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Password', 'easy-wp-smtp');
        ?>
</th>
						<td>
							<input type='password' name='swpsmtp_smtp_password' value='<?php 
        echo esc_attr(swpsmtp_get_password());
        ?>
' /><br />
							<span class="swpsmtp_info"><?php 
        _e("The password to login to your mail server", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
				</table>
				<p class="submit">
					<input type="submit" id="settings-form-submit" class="button-primary" value="<?php 
        _e('Save Changes', 'easy-wp-smtp');
        ?>
" />
					<input type="hidden" name="swpsmtp_form_submit" value="submit" />
					<?php 
        wp_nonce_field(plugin_basename(__FILE__), 'swpsmtp_nonce_name');
        ?>
				</p>				
			</form>
			
			<div class="updated fade" <?php 
        if (empty($result)) {
            echo "style=\"display:none\"";
        }
        ?>
>
				<p><strong><?php 
        echo $result;
        ?>
</strong></p>
			</div>
			<h3><?php 
        _e('Testing And Debugging Settings', 'easy-wp-smtp');
        ?>
</h3>
			<form id="swpsmtp_settings_form" method="post" action="">					
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php 
        _e("To", 'easy-wp-smtp');
        ?>
:</th>
						<td>
							<input type="text" name="swpsmtp_to" value=""/><br />
							<span class="swpsmtp_info"><?php 
        _e("Enter the email address to recipient", 'easy-wp-smtp');
        ?>
</span>
					</td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php 
        _e("Subject", 'easy-wp-smtp');
        ?>
:</th>
						<td>
							<input type="text" name="swpsmtp_subject" value=""/><br />
							<span  class="swpsmtp_info"><?php 
        _e("Enter a subject for your message", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php 
        _e("Message", 'easy-wp-smtp');
        ?>
:</th>
						<td>
							<textarea name="swpsmtp_message" id="swpsmtp_message" rows="5"></textarea><br />
							<span  class="swpsmtp_info"><?php 
        _e("Write your message", 'easy-wp-smtp');
        ?>
</span>
						</td>
					</tr>				
				</table>
				<p class="submit">
					<input type="submit" id="settings-form-submit" class="button-primary" value="<?php 
        _e('Send Test Email', 'easy-wp-smtp');
        ?>
" />
					<input type="hidden" name="swpsmtp_test_submit" value="submit" />
					<?php 
        wp_nonce_field(plugin_basename(__FILE__), 'swpsmtp_nonce_name');
        ?>
				</p>				
			</form>
		</div><!--  #swpsmtp-mail .swpsmtp-mail -->
	<?php 
    }
Esempio n. 2
0
    function swpsmtp_settings()
    {
        $display_add_options = $message = $error = $result = '';
        $swpsmtp_options = get_option('swpsmtp_options');
        if (isset($_POST['swpsmtp_form_submit']) && check_admin_referer(plugin_basename(__FILE__), 'swpsmtp_nonce_name')) {
            $swpsmtp_options['from_name_field'] = isset($_POST['swpsmtp_from_name']) ? sanitize_text_field(wp_unslash($_POST['swpsmtp_from_name'])) : '';
            if (isset($_POST['swpsmtp_from_email'])) {
                if (is_email($_POST['swpsmtp_from_email'])) {
                    $swpsmtp_options['from_email_field'] = $_POST['swpsmtp_from_email'];
                } else {
                    $error .= " " . __("Please enter a valid email address in the 'FROM' field.", 'akil_mail');
                }
            }
            $swpsmtp_options['smtp_settings']['host'] = sanitize_text_field($_POST['swpsmtp_smtp_host']);
            $swpsmtp_options['smtp_settings']['type_encryption'] = isset($_POST['swpsmtp_smtp_type_encryption']) ? $_POST['swpsmtp_smtp_type_encryption'] : 'none';
            $swpsmtp_options['smtp_settings']['autentication'] = isset($_POST['swpsmtp_smtp_autentication']) ? $_POST['swpsmtp_smtp_autentication'] : 'yes';
            $swpsmtp_options['smtp_settings']['username'] = sanitize_text_field($_POST['swpsmtp_smtp_username']);
            $smtp_password = trim($_POST['swpsmtp_smtp_password']);
            $swpsmtp_options['smtp_settings']['password'] = base64_encode($smtp_password);
            if (isset($_POST['swpsmtp_smtp_port'])) {
                if (empty($_POST['swpsmtp_smtp_port']) || 1 > intval($_POST['swpsmtp_smtp_port']) || !preg_match('/^\\d+$/', $_POST['swpsmtp_smtp_port'])) {
                    $swpsmtp_options['smtp_settings']['port'] = '25';
                    $error .= " " . __("Please enter a valid port in the 'SMTP Port' field.", 'akil_mail');
                } else {
                    $swpsmtp_options['smtp_settings']['port'] = $_POST['swpsmtp_smtp_port'];
                }
            }
            if (empty($error)) {
                update_option('swpsmtp_options', $swpsmtp_options);
                $message .= __("Settings saved.", 'akil_mail');
            } else {
                $error .= " " . __("Settings are not saved.", 'akil_mail');
            }
        }
        if (isset($_POST['swpsmtp_test_submit']) && check_admin_referer(plugin_basename(__FILE__), 'swpsmtp_nonce_name')) {
            if (isset($_POST['swpsmtp_to'])) {
                if (is_email($_POST['swpsmtp_to'])) {
                    $swpsmtp_to = $_POST['swpsmtp_to'];
                } else {
                    $error .= " " . __("Please enter a valid email address in the 'FROM' field.", 'akil_mail');
                }
            }
            $swpsmtp_subject = isset($_POST['swpsmtp_subject']) ? $_POST['swpsmtp_subject'] : '';
            $swpsmtp_message = isset($_POST['swpsmtp_message']) ? $_POST['swpsmtp_message'] : '';
            if (!empty($swpsmtp_to)) {
                $result = swpsmtp_test_mail($swpsmtp_to, $swpsmtp_subject, $swpsmtp_message);
            }
        }
        ?>
		<div class="swpsmtp-mail wrap" id="swpsmtp-mail">
			<div id="icon-options-general" class="icon32 icon32-bws"></div>
			<h2><?php 
        _e("Akil Mail Settings", 'akil_mail');
        ?>
</h2>
                        
			<div class="updated fade" <?php 
        if (empty($message)) {
            echo "style=\"display:none\"";
        }
        ?>
>
				<p><strong><?php 
        echo $message;
        ?>
</strong></p>
			</div>
			<div class="error" <?php 
        if (empty($error)) {
            echo "style=\"display:none\"";
        }
        ?>
>
				<p><strong><?php 
        echo $error;
        ?>
</strong></p>
			</div>
			<div id="swpsmtp-settings-notice" class="updated fade" style="display:none">
				<p><strong><?php 
        _e("Notice:", 'akil_mail');
        ?>
</strong> <?php 
        _e("The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'akil_mail');
        ?>
</p>
			</div>
			<h3><?php 
        _e('General Settings', 'akil_mail');
        ?>
</h3>
			<form id="swpsmtp_settings_form" method="post" action="">					
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php 
        _e("From Email Address", 'akil_mail');
        ?>
</th>
						<td>
							<input type="text" name="swpsmtp_from_email" value="<?php 
        echo esc_attr($swpsmtp_options['from_email_field']);
        ?>
"/><br />
					</td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php 
        _e("From Name", 'akil_mail');
        ?>
</th>
						<td>
							<input type="text" name="swpsmtp_from_name" value="<?php 
        echo esc_attr($swpsmtp_options['from_name_field']);
        ?>
"/><br />
						</td>
					</tr>			
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Host', 'akil_mail');
        ?>
</th>
						<td>
							<input type='text' name='swpsmtp_smtp_host' value='<?php 
        echo esc_attr($swpsmtp_options['smtp_settings']['host']);
        ?>
' /><br />
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('Type of Encription', 'akil_mail');
        ?>
</th>
						<td>
							<label for="swpsmtp_smtp_type_encryption_1"><input type="radio" id="swpsmtp_smtp_type_encryption_1" name="swpsmtp_smtp_type_encryption" value='none' <?php 
        if ('none' == $swpsmtp_options['smtp_settings']['type_encryption']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('None', 'akil_mail');
        ?>
</label>
							<label for="swpsmtp_smtp_type_encryption_2"><input type="radio" id="swpsmtp_smtp_type_encryption_2" name="swpsmtp_smtp_type_encryption" value='ssl' <?php 
        if ('ssl' == $swpsmtp_options['smtp_settings']['type_encryption']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('SSL', 'akil_mail');
        ?>
</label>
							<label for="swpsmtp_smtp_type_encryption_3"><input type="radio" id="swpsmtp_smtp_type_encryption_3" name="swpsmtp_smtp_type_encryption" value='tls' <?php 
        if ('tls' == $swpsmtp_options['smtp_settings']['type_encryption']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('TLS', 'akil_mail');
        ?>
</label><br />
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Port', 'akil_mail');
        ?>
</th>
						<td>
							<input type='text' name='swpsmtp_smtp_port' value='<?php 
        echo esc_attr($swpsmtp_options['smtp_settings']['port']);
        ?>
' /><br />
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Authentication', 'akil_mail');
        ?>
</th>
						<td>
							<label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='no' <?php 
        if ('no' == $swpsmtp_options['smtp_settings']['autentication']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('No', 'akil_mail');
        ?>
</label>
							<label for="swpsmtp_smtp_autentication"><input type="radio" id="swpsmtp_smtp_autentication" name="swpsmtp_smtp_autentication" value='yes' <?php 
        if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        _e('Yes', 'akil_mail');
        ?>
</label><br />
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP username', 'akil_mail');
        ?>
</th>
						<td>
							<input type='text' name='swpsmtp_smtp_username' value='<?php 
        echo esc_attr($swpsmtp_options['smtp_settings']['username']);
        ?>
' /><br />
						</td>
					</tr>
					<tr class="ad_opt swpsmtp_smtp_options">
						<th><?php 
        _e('SMTP Password', 'akil_mail');
        ?>
</th>
						<td>
							<input type='password' name='swpsmtp_smtp_password' value='<?php 
        echo swpsmtp_get_password();
        ?>
' /><br />
						</td>
					</tr>
				</table>
				<p class="submit">
					<input type="submit" id="settings-form-submit" class="button-primary" value="<?php 
        _e('Save Changes', 'akil_mail');
        ?>
" />
					<input type="hidden" name="swpsmtp_form_submit" value="submit" />
					<?php 
        wp_nonce_field(plugin_basename(__FILE__), 'swpsmtp_nonce_name');
        ?>
				</p>				
			</form>
			<div class="updated fade" <?php 
        if (empty($result)) {
            echo "style=\"display:none\"";
        }
        ?>
>
				<p><strong><?php 
        echo $result;
        ?>
</strong></p>
			</div>
			<h3><?php 
        _e('Testing And Debugging Settings', 'akil_mail');
        ?>
</h3>
			<form id="swpsmtp_settings_form" method="post" action="">					
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php 
        _e("To", 'akil_mail');
        ?>
:</th>
						<td>
							<input type="text" name="swpsmtp_to" value=""/><br />
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php 
        _e("Subject", 'akil_mail');
        ?>
:</th>
						<td>
							<input type="text" name="swpsmtp_subject" value=""/><br />
						</td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php 
        _e("Message", 'akil_mail');
        ?>
:</th>
						<td>
							<textarea name="swpsmtp_message" id="swpsmtp_message" rows="5"></textarea><br />
						</td>
					</tr>				
				</table>
				<p class="submit">
					<input type="submit" id="settings-form-submit" class="button-primary" value="<?php 
        _e('Send Test Email', 'akil_mail');
        ?>
" />
					<input type="hidden" name="swpsmtp_test_submit" value="submit" />
					<?php 
        wp_nonce_field(plugin_basename(__FILE__), 'swpsmtp_nonce_name');
        ?>
				</p>				
			</form>
		</div><!--  #swpsmtp-mail .swpsmtp-mail -->
	<?php 
    }