Miva Merchant Development by Scot's Scripts

EMAIL: Send Email from Template or Module

Miva Knowledge Base
EMAIL: Send Email from Template or Module

WARNING:

This information is offered "AS IS" for internal reference only. Use at your own risk.
Does AI actually understand your Miva Merchant store? Our smart JSON-LD schema generator makes sure it does. Contact us to get started. (more info)

EMAIL: Send Email from Template or Module

Scot Ranney • August 15, 2024 (updated: August 07, 2026)


THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED;
THE AUTHOR DISCLAIMS ALL LIABILITY FOR ANY DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR STORE DISRUPTIONS ARISING FROM ITS USE.


Send a Merchant Email Template as Email

This is the proper way to get an email out from a module: https://github.com/Raghu2407/Miva-Custom-Email-Template-Code

This is template code but can easily be used in a module using regular mivascript.

Note about template code: I've noticed that if the email template code is email_custom_code you need to drop the email part and  just use custom_code when loading the template.

Template MVT Code:

<mvt:assign name="l.run:override_subject" value="'Custom Subject'" />
<mvt:assign name="l.run:override_to" value="'customemail@example.com'" />
<mvt:do file="g.Module_Root $ '/modules/fulfill/templateorderemails.mvc'" name="l.success" value="TemplateOrderEmail_Load_Code('edit-order-email', l.email_template)" />
<mvt:do file="g.Module_Root $ '/modules/fulfill/templateorderemails.mvc'" name="l.success" value="TemplateOrderEmails_SendEmail(l.run, l.email_template)" />

Mivascript, for use in a module:

<MvASSIGN NAME = "l.run:override_subject" VALUE = "{ 'Custom Subject' }" />
<MvASSIGN NAME = "l.run:override_to" VALUE = "{ 'customemail@example.com' }" />
<MvASSIGN NAME = "l.ok" VALUE = "{ [ g.Module_Root $ '/modules/fulfill/templateorderemails.mvc'].TemplateOrderEmail_Load_Code('some-email-template-code', l.email_template) }" />
<MvIF EXPR = "{ l.email_template }">
	<MvASSIGN NAME = "l.ok" VALUE = "{ [ g.Module_Root $ '/modules/fulfill/templateorderemails.mvc'].TemplateOrderEmails_SendEmail(l.run, l.email_template) }" />
<MvELSE>
	Email template not found.
</MvIF>

Old Style Email: Send using the Send_Email  using a custom function. There is no point of doing it this way any longer.

Module code:

<MIVA STANDARDOUTPUTLEVEL = "compresswhitespace,text,html">
<MvCAPTURE VARIABLE = "l.email:message">
	This will be a text email message.
	<MvEVAL EXPR = "{ asciichar(10) }">
	Another line in the email message.
</MvCAPTURE>	 
<MIVA STANDARDOUTPUTLEVEL = "">
<MvASSIGN NAME = "l.email:subject" VALUE = "{ 'A subject for The Email' }" />
<MvASSIGN NAME = "l.email:to" VALUE = "{ 'someonesemail@domain.com' }" />   
<MvASSIGN NAME = "l.ok" VALUE = "{ send_email(l.email) }" />
<MvFUNCTION NAME = "send_email" PARAMETERS = "email" STANDARDOUTPUTLEVEL="">	
	<MvASSIGN NAME = "l.lf_single" VALUE = "{ asciichar(10) }" />
	<MvASSIGN NAME = "l.lf_double" VALUE = "{ asciichar(10) $ asciichar(10) }" />
	<MvIF EXPR = "{ NOT l.email:from }">
		<MvASSIGN NAME = "l.email:from" VALUE = "{ g.store:email }" />
		<MvASSIGN NAME = "l.email:from_name" VALUE = "{ g.store:name }" />		
	</MvIF>
	<MvIF EXPR = "{ l.headers }">
		<MvCAPTURE VARIABLE = "l.headers_parsed">
			<MvFOREACH ITERATOR = "l.header" INDEX = "l.headerpos" ARRAY = "l.headers">
				<MvEVAL EXPR = "{ l.header }">
				<MvEVAL EXPR = "{ l.lf_single }">
			</MvFOREACH>
		</MvCAPTURE>
		<MvASSIGN NAME = "l.message" VALUE = "{ l.message $ 'ShipNetwork Return Headers: ' $ l.lf_double $ l.headers_parsed $ l.lf_double }" />		
	</MvIF>
	<MvASSIGN NAME = "l.mailok" VALUE = "{ [ g.Module_Library_Utilities ].sendemail(l.email:to,l.email:from,l.nulll,l.email:subject,l.email:headers,l.email:message) }" />
	<MvFUNCRETURN VALUE = "{ l.mailok }">
</MvFUNCTION>

This calls the miva merchant api text email function so it can only be used from a module or template.


https://www.scotsscripts.com/mvblog/email-simple-module-mivascript-function-to-send-email.html

mvkb_module mvkb_email mvkb_mivascript