Jump to content

sending EMail Problem


jahyax

Recommended Posts

I'm trying to create a custom form (module) that a customer would fill up, and then send email , current I just used to input form and a submit button, when click there is no error,but no email sent or receive.

 

**Note: this is similar to send a friend module (but I am planning to ad more input form)

 

this  is my display.tpl

 

<script type="text/javascript">
 
{literal}
$('document').ready(function(){
$('#sendQuote').click(function(){
 
var name1 = $('#name1').val();
var email = $('#email').val();
 
if (name1 && email)
{
$.ajax({
 
{/literal}url:"{$my_quotation_link}"{literal},
type: "POST",
headers: {"cache-control": "no-cache"},
data: {action: 'sendQuote', name1:name1, email:email},
dataType: "json",
success: function(result){
console.log(email);
console.log('Hello');
}
});
}else{
console.log('Fail');
}
});
});
{/literal}
</script>
This is Lumberyard
<br/>
<form method="post" action="{request_uri}" class="lmbr">
{l s="Name"} <input id="name1" name="name1" type="text" name="name1" value="" size="14" />
{l s="Name"} <input id="email" name="email" type="text" name="email" value="" size="20" />
<input id="sendQuote" class="button" name="sendQuote" type="submit" value="Send Quotation" />
</form>
 
and this is my quotation ajax
 
 <?php
 
 
 
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
include_once(dirname(__FILE__).'/mymodule.php');
 
$module = new MyModule();
 
if (Tools::getValue('action') == 'sendQuote')
{
$name1 = Tools::getValue('name1');
$email = Tools::getValue('email');
 
}else{
$name1 = 'Name1';
$email = 'email';
 
}
 
 
$templateVars = array(
'{name1}' => Tools::safeOutput($name1),
'{email}' => Tools::safeOutput($email)
 
);
 
 
if (!Mail::Send((int)$module->context->cookie->id_lang,
 
'send_quote',
'Quotation',
$templateVars, $email,
null,
($module->context->cookie->email ? $module->context->cookie->email : null),
null,
null,
null,
dirname(__FILE__).'/mails/'))
die('0');
die('1');
 
 
die('0');
 
 
 
?>
 
I am also attaching my complete module for your reference

mymodule.zip

Link to comment
Share on other sites

You do not need init.php since it is depricated. The syntax for sending mails:

 

$mail = Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')),
       '{template}',
       '{subject}',
       array(
         {smartyname} => {value}
       ), 
       "{receiver}",
       "{receivername}", "{sender}", "{sendername}", "{attachments}", "{SMTP mode (true/false)}", "{template directory}");
 
Also you can look at the returnvalue of the mail variable ($mail = Mail::send).
 
Also try and test if your shop can send mail. Make a test order and see if you get feedback
  • Like 1
Link to comment
Share on other sites

thanks for the reply, I will check this out, but somehow I have a related issue, it seems that when posting via javascript, it is having an error like

POST: <url> 404 (not Found)

 

from what i have understand on error,it cannot find the file(php file),but when i check the url, where my javascript will supposed to POST , the file is there

Link to comment
Share on other sites

Thanks for helping out,

 

I manage to solve Post method problem from javascript by correcting the right path where my php file is located like " url : '{$base_dir}modules/modulename/file-name.php' "

and using the Send mail syntax that "jsmit2" posted I was able to send an email.

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...