Jump to content

Send a email with prestashop code


bahamont

Recommended Posts

i tried that, but i don't receive any email:

 

mail("[email protected]", $text,$text)

 

take a look on function definition:

 

/**

* Send Email
* @param int $id_lang Language of the email (to translate the template)
* @param string $template Template: the name of template not be a var but a string !
* @param string $subject
* @param string $template_vars
* @param string $to
* @param string $to_name
* @param string $from
* @param string $from_name
* @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
* @param bool $modeSMTP
* @param string $template_path
* @param bool $die
         * @param string $bcc Bcc recipient
*/
public static function Send($id_lang, $template, $subject, $template_vars, $to,
$to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null,
$template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null)
Link to comment
Share on other sites

First, make sure your Prestashop was able to send email, and then try this :

public function install()
{
     Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
        'contact', // email template file to be use
        $this->displayName.' Module Installation', // 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
        ), 
        '[email protected]', // receiver email address 
        NULL, NULL, NULL);
                
     // Your module installation process here
}
Edited by gonebdg - webindoshop.com (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

 

First, make sure your Prestashop was able to send email, and then try this :

public function install()
{
     Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
        'contact', // email template file to be use
        $this->displayName.' Module Installation', // 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
        ), 
        '[email protected]', // receiver email address 
        NULL, NULL, NULL);
                
     // Your module installation process here
}

 

The template my email is in a folder within the module itself. Is there any way to tell the path of template?

 

I have installed prestashop in a local server and got this error message when installing the module:

 

[2] mail (): Failed to connect to mailserver at "localhost" port 25, Verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set ()

 

Is it because I have a local server?

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

The template my email is in a folder within the module itself. Is there any way to tell the path of template?

 

I have installed prestashop in a local server and got this error message when installing the module:

 

[2] mail (): Failed to connect to mailserver at "localhost" port 25, Verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set ()

 

Is it because I have a local server?

 

yes, it's because you're on localhost

if you haven't got on your localhost any smtp service - it will not work.

you can try to use SMTP connection to some remote service like gmail

you can set it up under adv. parameters > mail tab in back office.

Link to comment
Share on other sites

The template my email is in a folder within the module itself. Is there any way to tell the path of template?

Take a look on Vekia post above, @param string $template_path

http://www.prestashop.com/forums/topic/330853-send-a-email-with-prestashop-code/?do=findComment&comment=1674051

You will need to add/define the parameter $template_path if you wanna use custom email template file which placed in your module directory

 

Is it because I have a local server?

if you're use Xampp, don't forget to activate and configure Mercury module also don't forget to install Free and Open Source Webmail Software, like Rouncube on your localhost.

Otherwise you won't be able to send/receive/read email within your localhost system.
I hope you're understand how to use Xampp-Mercury module

Link to comment
Share on other sites

I create the $template_patch variable,but prestashop don't search in that url

 

This is the code:

 $template_path = dirname(__FILE__).'/mails/';

            Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
        'template', // email template file to be use
        $this->displayName.' Module Installation', // 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
        ),
        '[email protected]', // receiver email address
        NULL, NULL, NULL,
        $template_path);

Prestashop search in: C:\Users\name_user\www\prestashop/mails/es/template.txt

 

The file is in: C:\Users\name_user\www\prestashop/modules/name_module/mails/es/template.txt

 

What is wrong?

Edited by bahamont (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...