I have a function that uses mail() to send emails where I only need to supply the email address, subject, message and format. Format being text based or html based, which works fines.

I use two language files at the moment plain-text emails and html based emails with subjects and message bodys incased in variable $mail;

i.e $mail['verification_email_subject'] = 'Verification required';

Anywho instead of writing out in every necessary place where we are going to send emails, I didn't want to have to write;

include_once ROOT_PATH.'languages/english/plain-text.mail'; or the opposite for html based email.

So I decided to write a small function based on "mailformat ($format)", where if $format equals to 'text' based email it will include the plain-text.mail file otherwise include the html based mail file.

The only thing is if there is a variable in the message for example I have to globalize the variable to make it available within the function and globalize $mail to make it accessible outside the function.

ie. $mail['verification_email_subject'] = 'Verification required for ' . $sitename;

function mailformat ( $format )
{
    global $mail, $sitename;

  if ( $format == 'text' )
{
   include_once ROOT_PATH . 'languages/english/plain-text.mail';
}
else
{
   include_once ROOT_PATH . 'languages/english/html-text.mail';
}
}

for instance.

Is there a better way to do this? As the global variables could get rather long?

    Write a Reply...