Hello a tous j'ai créer un plugin pour mon chouchou
il permet d'ajouter un constructeur de champs pour générer un formulaire
Tout semble fonctionner sauf que je n'arrive pas generer des copy d'email, l'email principal arrive nikel
je ne comprend pas pour l'email a l'administrateur et l'email en copie ne partent pas .....
j'ai essayer de m'inspiré de la fonction com_contact de joomla .. rien ne sort
des idées ?
il permet d'ajouter un constructeur de champs pour générer un formulaire
Tout semble fonctionner sauf que je n'arrive pas generer des copy d'email, l'email principal arrive nikel
Code PHP:
// set only form value in input
$id = $jinput->post->get('formid', '', '');
$datas = $jinput->post->get($id, array(), 'array');
if (isset($datas['name'])){
$name = $datas['name'];
}
if (isset($datas['firstname'])){
$firstname = $datas['firstname'];
}
if (isset($datas['lastname'])){
$lastname = $datas['lastname'];
}
// Create header email
if (!empty($name)){ // check if user use 1 name field or 2 separeate field
$fromname = $datas['name'];
} elseif (!empty($firstname) && !empty($lastname)){
$firstname = $datas['firstname'];
$lastname = $datas['lastname'];
$fromname = $firstname.' '.$lastname;
}
if (empty($fromname)){
$app->enqueueMessage(JText::_('FLEXI_FIELD_EMAIL_CONFIG _ERROR'), 'error');
}
$fromemail = $jinput->post->get('emailfrom', '', '');
$emailauthor = $jinput->post->get('emailauthor', '', '');
$from = array($fromemail , $fromname);
//subject
if (isset($datas['subject'])){
$subject = $datas['subject'];
} else{
$subject ='';
}
$subjectemail = JText::sprintf('FLEXI_FIELD_EMAIL_SUBJECT_DEFAULT' , $fromname, $subject);
//body
$body = '';
foreach ($datas as $field => $value) {
$body .= '<li>' . $value . '</li>';
}
$body = "\n\r\n\r\n" . stripslashes($body);
$message = JText::sprintf('FLEXI_FIELD_EMAIL_MESSAGE_DEFAULT' , $title, $body, '<a href="'.$item_url.'">'.$item_url.'</a>', $sitename);
// Check whether email copy function activated
$copy_email_user = $pluginParams->get( 'email_user_copy');
if ($copy_email_user == 1)
{
$messagecopy = JText::sprintf('FLEXI_FIELD_EMAIL_MESSAGE_DEFAULT_ COPY', $title, $body, '<a href="'.$item_url.'">'.$item_url.'</a>', $sitename);
$subjectcopy = JText::sprintf('FLEXI_FIELD_EMAIL_SUBJECT_DEFAULT_COPY', $fromname, $itemauthor, $subject);
$mailer = JFactory::getMailer();
$mailer->isHTML(true);
$mailer ->setSender(array($emailauthor, $itemauthor));
$mailer ->addRecipient($fromemail);
$mailer ->setSubject($subjectcopy);
$mailer ->setBody($messagecopy);
$send = $mailer->Send();
}
$copy_email_admin = $pluginParams->get( 'email_admin_copy');
$email_admin = $pluginParams->get( 'email_admin' ) ;
if ($copy_email_admin == 1)
{
$messagecopyadmin = JText::sprintf('FLEXI_FIELD_EMAIL_MESSAGE_ADMIN_COPY', $fromname , $title, $body, '<a href="'.$item_url.'">'.$item_url.'</a>', $sitename);
$subjectcopyadmin = JText::sprintf('FLEXI_FIELD_EMAIL_SUBJECT_ADMIN_COPY', $itemauthor, $subject);
$mailer = JFactory::getMailer();
$mailer->isHTML(true);
$mailer ->setSender($from, $fromname);
$mailer ->addRecipient($email_admin);
$mailer ->setSubject($subjectcopyadmin);
$mailer ->setBody($messagecopyadmin);
$send = $mailer->Send();
}
//Prepare contact email
$mailer = JFactory::getMailer();
$mailer->isHTML(true);
$mailer->setSender($from, $fromname);
$mailer->addRecipient($emailauthor);
$mailer->setSubject($subjectemail);
$mailer->setBody($message);
//upload attachement
$files = $jinput->files->get($formid);
if (isset($files))
{
JFolder::create(JPATH_SITE . DS . "tmp" . DS . "upload_flexi_form". $formid);
foreach($files as $attachements) {
foreach ($attachements as $file){
// Import filesystem libraries. Perhaps not necessary, but does not hurt.
jimport('joomla.filesystem.file');
// Clean up filename to get rid of strange characters like spaces etc.
$filename = JFile::makeSafe($file['name']);
// Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = JPATH_SITE . DS . "tmp" . DS . "upload_flexi_form". $formid . DS . $filename;
// TODO: Add security checks. FIle extension and size maybe using flexicontent helper
if (JFile::upload($src, $dest))
{
$mailer->addAttachment($dest);
}
else
{
$app->enqueueMessage(JText::_('FLEXI_FIELD_EMAIL_MESSAG E_SEND_ERROR'), 'error');
}
}
}
}
//Sendemail
$send = $mailer->Send();
//Message in front-end
if ( $send !== true )
{
$app->enqueueMessage(JText::_('FLEXI_FIELD_EMAIL_MESSAGE_SEND_ERROR'), 'error');
$destFolder= JPATH_SITE . DS . "tmp" . DS . "upload_flexi_form". $formid;
//Deleting file
if (is_dir($destFolder)) {
JFolder::delete($destFolder);
}
} else {
// Message sending
$app->enqueueMessage(JText::_('FLEXI_FIELD_EMAIL_MESSAG E_SEND_SUCCESS'), 'message');
//Deleting file
if (is_dir($$destFolder)) {
JFolder::delete($destFolder);
}
}
}
j'ai essayer de m'inspiré de la fonction com_contact de joomla .. rien ne sort
des idées ?
Commentaire