On submit form send record to email

Hi am is Siddhartha,
i have a form with some fields and my requirement is when i submit that form an email has to send along with the form details what we entered. So i want to know is their any possibility for my requirement please suggest.

Hi Siddhartha,

You could likely just create a workflow that sends an email, when a new record is created.

If you wanted to make it so that the workflow only sends an email if a record is created via WebToLead form, a possible solution could be to create a custom checkbox field that records whether or not the field was created in the CRM or if it was Generated via WebtoLead Form, then have the workflow use that Checkbox as a condition.

Hopefully that makes sense and gives you some ideas.

Thanks for the reply.

I am able to create the workflow with email action. However, I am puzzled with another issue now. Basically, I am able to select fields from a single module, but not from the modules in relationship.

For example, I have employees and departments modules. employees has got many-to-one relation with departments. If I create workflow on employees, I can see all the data in employees module, but I need to pull department name from departments module. Ideas please.

Thanks a ton!

You could do it in an after save logic hook

I couldn’t get that… would you elaborate little bit please?

Rather than using workflow you could create an after_save logic hook

In that you pull all the data you need together and send an email

What I do is use email templates as a template

See my code below


// get template
		$et = new EmailTemplate ();
		
		$et->retrieve_by_string_fields ( array (
				'name' => 'Case Notification' 
		) );
		
		$body = $et->body_html;
		$body = $TplReplace ( $body, $bean, 'cases' );
		$subject = $et->subject;
		$subject = $TplReplace ( $subject, $bean, 'cases' );
		
		$user = BeanFactory::getBean ( 'Users', $bean->assigned_user_id );
		$primary_email = $user->emailAddress->getPrimaryAddress ( $user );
		
		$from = $bean->to_addrs;
		if (! $from) {
			$user = BeanFactory::getBean ( 'Users', $bean->modified_user_id );
			$from = $user->emailAddress->getPrimaryAddress ( $user );
		}
		
		$mail = array (
				'subject' => $subject,
				'Body_html' => from_html ( $body ),
				'body' => wordwrap ( $body, 900 ),
				'from' => $from,
				'to' => array (
						$primary_email 
				),
				'FromName' => $bean->assigned_user_name 
		);
		$SendMail ( $mail, true );
		// --------------------------------------------------------------------------------------------
		function TplReplace($text, $bean, $tpl) {
		// replace varial - used for em,ail templates
		
		// create href_link
		global $app_list_strings;
		global $sugar_config;
		
		$link = "{$sugar_config['site_url']}/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}";
		
		$bean->href_link = "<a href=\"$link\">Click Here</a>";
		
		foreach ( $bean as $k => $v ) {
			if (is_string ( $v ))
				$text = preg_replace ( "/\{$tpl::$k\}/", $v, $text );
		}
		
		return $text;
	}
	
	// --------------------------------------------------------------------------------------------
	function SendMail($mail, $html = false) {
		require_once ('include/SugarPHPMailer.php');
		$note_msg = new SugarPHPMailer ();
		$note_msg->Subject = $mail ['subject'];
		$note_msg->prepForOutbound ();
		$note_msg->setMailerForSystem ();
		$note_msg->Body = $mail ['body'];
		$note_msg->From = $mail ['from'];
		
		// $GLOBALS ['log']->fatal ( 'from: ' . $mail ['from'] );
		// $GLOBALS ['log']->fatal ( 'fromname: ' . $mail ['FromName'] );
		
		$note_msg->FromName = preg_replace ( '/<.*>/', '', $mail ['FromName'] );
		$note_msg->IsHTML ( $html );
		if ($html == true)
			$note_msg->Body_html = $mail ['Body_html'];
		
		foreach ( $mail ['to'] as $to )
			$note_msg->AddAddress ( $to );
		
		foreach ( $mail ['cc'] as $cc )
			$note_msg->AddCC ( $cc );
		
		$note_msg->prepForOutbound ();
		$note_msg->setMailerForSystem ();
		
		if (! $note_msg->Send ()) {
			$GLOBALS ['log']->fatal ( 'Error sending e-mail: ' . $note_msg->ErrorInfo );
		}
	}