Jump to content

Sending an e-mail from a custom module.


LilBe

Recommended Posts

Hi, I'm trying to create a module which is a quiz. The quiz works and all, but when the user chooses the right answer, I want to receive an email with his details so I would know who won a discount.

 

i have 2 php files

 

sendemail.php

<?php
 
global function sendMails() {
 
Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
 
        'castigator', // email template file to be use
 
        $this->displayName.' Quiz winner', // email subject
 
        array(
 
          '{email}' => Configuration::get('PS_SHOP_EMAIL'), // sender email address
 
          '{message}' => $this->displayName.' has been installed on:'._PS_BASE_URL_.__PS_BASE_URI__ // email content
 
        ), 
 
        '*myemail*', // receiver email address 
 
        NULL, NULL, NULL);
 
}
}
 
?>

The format isn't configured properly yet, I just want it to send any email.

 

 

quiz.php

<div class="block">
 <h4>Quiz</h4>
 <div class="block_content" style="padding:0px;">
 
{if $logged} 
 
<html>
<head>
</head>
<title>Quiz</title>
 
{literal}
 
<script language="JavaScript">
 
var raspunsc={/literal}"{$raspunscorect}"{literal};
 
function raspuns(form) {
 
  
  for(var i=0; i<3; i++)
  {
   element = form.elements[i];
   
   if(element.checked)
   {
    if(element.value===raspunsc)
    {
     document.getElementById("raspuns").innerHTML = "Raspuns corect";
     >>> THE sendMails FUNCTION SHOULD BE CALLED HERE (if the answer is correct, send an email with his details [username, email]) <<<
    }
    else
    {
     document.getElementById("raspuns").innerHTML = "Raspuns gresit";
    }
   }
  
  }
   
}
 
 
</script>
 
{/literal}
 
</head>
 
<body>
 
<form name="quiz">
{$cookie->email}
{$cookie->customer_firstname}
{$cookie->customer_lastname}
 
{$descriere}<br>
 
{$intrebare}<br>
 
<input type="radio" name="q1" value="{$raspuns1}">{$raspuns1}<br>
<input type="radio" name="q1" value="{$raspuns2}">{$raspuns2}<br>
<input type="radio" name="q1" value="{$raspuns3}">{$raspuns3}<br>
<p>
 
<input type="button" value="Raspunde" onClick="raspuns(this.form)">
 
<p id="raspuns"></p>
</form>
 
</body></html>
 
 </div>
</div>
 
{else}
{include file="./logare.html"}
{/if}

I've tried a lot of methods and I can't make the module send an email from that JavaScript function. How should I call my sendEmail function? I have an email template and another php file with the configuration page and all that.

 

Thank you.

Edited by LilBe (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...