#1 2016-06-12 05:58:30

fredericomarinho.com
Member
From: Juiz de Fora / Brazil
Registered: 2015-06-08
Posts: 40
Website

How can I confirm if a contact was sent?

Hello guys!

My website developed using IonizeCMS (http://www.tvitv.com.br) is working fine, even sending contacts! But, I realized that <ion:form:contact:validation:success... treat just the form validation, if there is some error in the fields. So, I tried to send a contact using the wrong email server configuration. The form confirmed that the email was sent (because the validation was ok) but it was not sent, actually.

Is there a way to know if the email was sent correctly, beyond than just validation form?

Thanks! Loving ionize...

Last edited by fredericomarinho.com (2016-06-12 05:58:39)


Frederico Marinho - Social Media and Web Developer
contato@fredericomarinho.com
fredericomarinho.com

Offline

#2 2016-06-12 10:03:59

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: How can I confirm if a contact was sent?

Hello,

modify the ./ application / libraries / Tagmanager / Email.php, add returns to the email sending:

<?php
/**
 * Ionize
 *
 * @package		Ionize
 * @author		Ionize Dev Team
 * @license		http://doc.ionizecms.com/en/basic-infos/license-agreement
 * @link		http://ionizecms.com
 * @since		Version 0.9.9
 *
 */


/**
 * Email TagManager
 *
 */
class TagManager_Email extends TagManager
{
	public static $tag_definitions = array();

	/**
	 * Sends Emails as defined in the forms.php config file.
	 * Important : This method receives the "form" tag
	 *
	 * @param FTL_Binding	Form tag
	 * @param string
	 * @param array       	Array of data send to the Email view.
	 * 						Each key of this array will be available in the view by :
	 * 						<ion:data:key />
	 *
	 * 						The passed array should look like this :
	 * 						array(
	 * 							'email' => 'user email',		// Email of the user (POST, DB...)
	 * 							'key1' => 'value1,				// Makes <ion:data:key1 /> available in the Email view
	 * 						);
	 *
	 */
	public static function send_form_emails(FTL_Binding $tag, $form_name, $data = array())
	{
		// Set the 'data' tag from the received data array
		self::$context->define_tag('data', array(__CLASS__, 'tag_expand'));

		foreach($data as $key=>$value)
			if ( ! is_array($value) && ! is_object($value))
				self::$context->define_tag('data:'.$key, array(__CLASS__, 'tag_simple_value'));

		// Get all declared emails configuration data from forms.php config file
		$emails = TagManager_Form::get_form_emails($form_name);

		// Get the 'sender' email : Must be set in Ionize : Settings > Advanced settings > Email
		$website_email = Settings::get('site_email') ? Settings::get('site_email') : NULL;

		// Send all defined emails
		foreach($emails as $email_setting)
		{
			$email = $email_setting['email'];
			$reply_to = isset($email_setting['reply_to']) ? $email_setting['reply_to'] : NULL;

			// Get potential website / form email
			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;
			}

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

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

					default:
						$reply_to = (Settings::get('email_'.$email) != '') ? Settings::get('email_'.$email) : NULL;
						break;
				}
			}

			// Send the email
			if ( $email )
			{
				// Subject, adds the website title as swap text : displayed in title if the %s key is used.
				$subject = lang($email_setting['subject'], Settings::get('site_title'));
				$data['subject'] = $subject;

				// Set the "data tag" array of data.
				$tag->set('data', $data);

				// Email Lib
				if ( ! isset(self::$ci->email)) self::$ci->load->library('email');
				self::$ci->email->clear();

				// Subject / From / To
				self::$ci->email->subject($subject);
				self::$ci->email->from($website_email, Settings::get("site_title"));
				self::$ci->email->to($email);

				if ( ! is_null($reply_to))
					self::$ci->email->reply_to($reply_to);

				// View & Message content
				$view_content = $tag->parse_as_standalone(self::$tag_prefix, Theme::load($email_setting['view']));

				self::$ci->email->message($view_content);

				// Send silently
				$result = @self::$ci->email->send();

				if ( ! $result)
				{
					log_message('error', 'Error : Tagmanager/Email->send_form_emails() : Email was not sent.');
				}
				
				return $result;
			}
			else
			{
				log_message('error', 'Error : Tagmanager/Email->send_form_emails() : Email not found');
				return FALSE;
			}
		}
	}
}

After the modification you can get the email success in your theme / libraries / FormName.php:

$email_sended = TagManager_Email::send_form_emails($tag, $form_name, $post);

Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

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