Tell me please. You need to make a form that will send an email data to email. I use joomla .

Created the file send_mail.php in the folder with the template.

Content:

 <? //defined('_JEXEC') or die; require_once '/libraries/joomla/mail/mail.php'; header("Content-type: text/plain; charset=utf-8"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); $mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $sender = array($config->getValue('mailfrom'), $config->getValue('fromname') ); $mailer->setSender($sender); $mailer->addRecipient('test@gmail.com'); $body = "Имя: ".$_POST['name'].'; Телефон: '.$_POST['phone']; $mailer->setSubject('Нужна бесплатная консультация'); $mailer->setBody($body); $send = $mailer->Send(); if ($send !== true) { echo 'Error sending email: '.$send->message; } else { echo 'Mail sent'; } ?> 

I send the request using ajax. When you click on the button. In the console I see http://site.ru/templates/test/send_mail.php 500 (Internal Server Error)

Why? where is the mistake?

Raised to the main page by a community spirit member 2 days ago .

This question contains answers that can be both good and bad; the system offered them for verification.

  • logs to the studio ... - Invision
  • @Invision do not have access to the machine. - Tsyklop

1 answer 1

You use the joomla-framework in the script without connecting it, the framework connects like this:

  // include joomla framework if (!defined('_JEXEC')) { define( '_JEXEC', 1 ); define('JPATH_BASE', '../'); // line 4 require_once ( JPATH_BASE .'/includes/defines.php' ); require_once ( JPATH_BASE .'/includes/framework.php' ); defined('DS') or define('DS', DIRECTORY_SEPARATOR); } 

This is for example when your file is in the root folder of joomla, otherwise you need to adjust the path (line 4)

And in the first line you have an error in the path - there can not be such a folder from the root of the file system:

 require_once '/libraries/joomla/mail/mail.php';