2013-09-23 13:17:31 +02:00
< ? php
/* Copyright ( C ) 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
* or see http :// www . gnu . org /
*/
/**
* \file htdocs / core / actions_sendmails . inc . php
* \brief Code for actions on sending mails from object page
*/
2016-09-26 14:08:14 +02:00
// $mysoc must be defined
2013-09-23 13:17:31 +02:00
// $id must be defined
// $actiontypecode must be defined
2014-08-05 09:26:40 +02:00
// $paramname must be defined
// $mode must be defined
2016-09-26 14:08:14 +02:00
// $object and $uobject may be defined.
2013-09-23 13:17:31 +02:00
/*
* Add file in email form
*/
if ( GETPOST ( 'addfile' ))
{
2016-06-24 16:10:52 +02:00
$trackid = GETPOST ( 'trackid' , 'aZ09' );
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2013-09-23 13:17:31 +02:00
// Set tmp user directory
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
2016-06-24 16:10:52 +02:00
$upload_dir_tmp = $vardir . '/temp' ; // TODO Add $keytoavoidconflict in upload_dir path
2013-09-23 13:17:31 +02:00
2016-06-24 16:10:52 +02:00
dol_add_file_process ( $upload_dir_tmp , 0 , 0 , 'addedfile' , '' , null , $trackid );
2013-09-23 13:17:31 +02:00
$action = 'presend' ;
}
/*
* Remove file in email form
*/
2015-08-24 16:05:15 +02:00
if ( ! empty ( $_POST [ 'removedfile' ]) && empty ( $_POST [ 'removAll' ]))
2013-09-23 13:17:31 +02:00
{
2016-06-24 16:10:52 +02:00
$trackid = GETPOST ( 'trackid' , 'aZ09' );
2013-09-23 13:17:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
// Set tmp user directory
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
2016-06-24 16:10:52 +02:00
$upload_dir_tmp = $vardir . '/temp' ; // TODO Add $keytoavoidconflict in upload_dir path
2013-09-23 13:17:31 +02:00
2016-06-24 16:10:52 +02:00
// TODO Delete only files that was uploaded from email form. This can be addressed by adding the trackid into the temp path then changing donotdeletefile to 2 instead of 1 to say "delete only if into temp dir"
// GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array.
dol_remove_file_process ( GETPOST ( 'removedfile' , 'alpha' ), 0 , 1 , $trackid ); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically
2013-09-23 13:17:31 +02:00
$action = 'presend' ;
}
2015-08-24 16:05:15 +02:00
/*
* Remove all files in email form
*/
2016-06-24 16:10:52 +02:00
if ( GETPOST ( 'removAll' ))
2015-08-24 16:05:15 +02:00
{
2016-06-24 16:10:52 +02:00
$trackid = GETPOST ( 'trackid' , 'aZ09' );
$listofpaths = array ();
2015-08-24 16:05:15 +02:00
$listofnames = array ();
$listofmimes = array ();
2016-06-24 16:10:52 +02:00
$keytoavoidconflict = empty ( $trackid ) ? '' : '-' . $trackid ;
if ( ! empty ( $_SESSION [ " listofpaths " . $keytoavoidconflict ])) $listofpaths = explode ( ';' , $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
if ( ! empty ( $_SESSION [ " listofnames " . $keytoavoidconflict ])) $listofnames = explode ( ';' , $_SESSION [ " listofnames " . $keytoavoidconflict ]);
if ( ! empty ( $_SESSION [ " listofmimes " . $keytoavoidconflict ])) $listofmimes = explode ( ';' , $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
2015-08-24 16:05:15 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
2016-06-24 16:10:52 +02:00
$formmail -> trackid = $trackid ;
2015-08-24 16:05:15 +02:00
foreach ( $listofpaths as $key => $value )
{
$pathtodelete = $value ;
$filetodelete = $listofnames [ $key ];
2016-09-20 12:19:17 +02:00
$result = dol_delete_file ( $pathtodelete , 1 ); // Delete uploded Files
2015-08-24 16:05:15 +02:00
$langs -> load ( " other " );
2015-11-19 13:59:58 +01:00
setEventMessages ( $langs -> trans ( " FileWasRemoved " , $filetodelete ), null , 'mesgs' );
2016-09-20 12:19:17 +02:00
2015-08-24 16:05:15 +02:00
$formmail -> remove_attached_files ( $key ); // Update Session
}
}
2013-09-23 13:17:31 +02:00
/*
* Send mail
*/
2015-08-24 16:35:08 +02:00
if (( $action == 'send' || $action == 'relance' ) && ! $_POST [ 'addfile' ] && ! $_POST [ 'removAll' ] && ! $_POST [ 'removedfile' ] && ! $_POST [ 'cancel' ] && ! $_POST [ 'modelselected' ])
2013-09-23 13:17:31 +02:00
{
2016-06-24 16:10:52 +02:00
$trackid = GETPOST ( 'trackid' , 'aZ09' );
2016-10-03 00:39:07 +02:00
$subject = '' ; $actionmsg = '' ; $actionmsg2 = '' ;
2016-06-24 16:10:52 +02:00
if ( ! empty ( $conf -> dolimail -> enabled )) $langs -> load ( " dolimail@dolimail " );
2013-09-23 13:17:31 +02:00
$langs -> load ( 'mails' );
2016-09-26 14:08:14 +02:00
if ( is_object ( $object ))
2013-09-23 13:17:31 +02:00
{
2016-09-26 14:08:14 +02:00
$result = $object -> fetch ( $id );
$sendtosocid = 0 ;
if ( method_exists ( $object , " fetch_thirdparty " ) && $object -> element != 'societe' )
{
$result = $object -> fetch_thirdparty ();
$thirdparty = $object -> thirdparty ;
$sendtosocid = $thirdparty -> id ;
}
else if ( $object -> element == 'societe' )
{
$thirdparty = $object ;
if ( $thirdparty -> id > 0 ) $sendtosocid = $thirdparty -> id ;
elseif ( $conf -> dolimail -> enabled )
{
$dolimail = new Dolimail ( $db );
$possibleaccounts = $dolimail -> get_societe_by_email ( $_POST [ 'sendto' ], " 1 " );
$possibleuser = $dolimail -> get_from_user_by_mail ( $_POST [ 'sendto' ], " 1 " ); // suche in llx_societe and socpeople
if ( ! $possibleaccounts && ! $possibleuser )
{
setEventMessages ( $langs -> trans ( 'ErrorFailedToFindSocieteRecord' , $_POST [ 'sendto' ]), null , 'errors' );
}
elseif ( count ( $possibleaccounts ) > 1 )
{
$sendtosocid = $possibleaccounts [ 1 ][ 'id' ];
$result = $object -> fetch ( $sendtosocid );
setEventMessages ( $langs -> trans ( 'ErrorFoundMoreThanOneRecordWithEmail' , $_POST [ 'sendto' ], $object -> name ), null , 'mesgs' );
}
else
{
if ( $possibleaccounts ){
$sendtosocid = $possibleaccounts [ 1 ][ 'id' ];
$result = $object -> fetch ( $sendtosocid );
} elseif ( $possibleuser ){
$sendtosocid = $possibleuser [ 0 ][ 'id' ];
$result = $uobject -> fetch ( $sendtosocid );
$object = $uobject ;
}
}
}
}
else dol_print_error ( '' , 'Use actions_sendmails.in.php for a type that is not supported' );
2013-09-23 13:17:31 +02:00
}
2016-09-26 14:08:14 +02:00
else $thirdparty = $mysoc ;
2013-09-23 13:17:31 +02:00
if ( $result > 0 )
{
2014-11-04 13:54:18 +01:00
if ( trim ( $_POST [ 'sendto' ]))
2013-09-23 13:17:31 +02:00
{
// Recipient is provided into free text
2014-11-04 13:54:18 +01:00
$sendto = trim ( $_POST [ 'sendto' ]);
2013-09-23 13:17:31 +02:00
$sendtoid = 0 ;
}
elseif ( $_POST [ 'receiver' ] != '-1' )
{
// Recipient was provided from combo list
if ( $_POST [ 'receiver' ] == 'thirdparty' ) // Id of third party
{
2016-10-24 02:02:30 +02:00
$sendto = $thirdparty -> name . ' <' . $thirdparty -> email . '>' ;
2013-09-23 13:17:31 +02:00
$sendtoid = 0 ;
}
else // Id du contact
{
2015-08-24 16:22:21 +02:00
$sendto = $thirdparty -> contact_get_property (( int ) $_POST [ 'receiver' ], 'email' );
2013-09-23 13:17:31 +02:00
$sendtoid = $_POST [ 'receiver' ];
}
}
2014-11-04 13:54:18 +01:00
if ( trim ( $_POST [ 'sendtocc' ]))
{
$sendtocc = trim ( $_POST [ 'sendtocc' ]);
}
elseif ( $_POST [ 'receivercc' ] != '-1' )
{
// Recipient was provided from combo list
if ( $_POST [ 'receivercc' ] == 'thirdparty' ) // Id of third party
{
2016-10-24 02:02:30 +02:00
$sendtocc = $thirdparty -> name . ' <' . $thirdparty -> email . '>' ;
2014-11-04 13:54:18 +01:00
}
else // Id du contact
{
2015-08-24 16:22:21 +02:00
$sendtocc = $thirdparty -> contact_get_property (( int ) $_POST [ 'receivercc' ], 'email' );
2014-11-04 13:54:18 +01:00
}
}
2013-09-23 13:17:31 +02:00
if ( dol_strlen ( $sendto ))
{
2016-10-24 02:02:30 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2013-09-23 13:17:31 +02:00
$langs -> load ( " commercial " );
2016-10-15 03:45:23 +02:00
$fromtype = GETPOST ( 'fromtype' );
if ( $fromtype === 'user' ) {
2016-10-13 16:44:17 +02:00
$from = $user -> getFullName ( $langs ) . ' <' . $user -> email . '>' ;
2016-10-15 03:45:23 +02:00
}
elseif ( $fromtype === 'company' ) {
2016-10-13 16:44:17 +02:00
$from = $conf -> global -> MAIN_INFO_SOCIETE_NOM . ' <' . $conf -> global -> MAIN_INFO_SOCIETE_MAIL . '>' ;
2016-10-15 03:45:23 +02:00
}
elseif ( preg_match ( '/user_aliases_(\d+)/' , $fromtype , $reg )) {
$tmp = explode ( ',' , $user -> email_aliases );
$from = trim ( $tmp [( $reg [ 1 ] - 1 )]);
}
elseif ( preg_match ( '/global_aliases_(\d+)/' , $fromtype , $reg )) {
$tmp = explode ( ',' , $conf -> global -> MAIN_INFO_SOCIETE_MAIL_ALIASES );
$from = trim ( $tmp [( $reg [ 1 ] - 1 )]);
2016-10-13 16:44:17 +02:00
}
else {
$from = $_POST [ 'fromname' ] . ' <' . $_POST [ 'frommail' ] . '>' ;
}
$replyto = $_POST [ 'replytoname' ] . ' <' . $_POST [ 'replytomail' ] . '>' ;
2013-09-23 13:17:31 +02:00
$message = $_POST [ 'message' ];
2014-11-04 13:54:18 +01:00
$sendtobcc = GETPOST ( 'sendtoccc' );
2015-04-01 12:22:50 +02:00
if ( $mode == 'emailfromproposal' ) $sendtobcc .= ( empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_PROPOSAL_TO ) ? '' : (( $sendtobcc ? " , " : " " ) . $conf -> global -> MAIN_MAIL_AUTOCOPY_PROPOSAL_TO ));
if ( $mode == 'emailfromorder' ) $sendtobcc .= ( empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_ORDER_TO ) ? '' : (( $sendtobcc ? " , " : " " ) . $conf -> global -> MAIN_MAIL_AUTOCOPY_ORDER_TO ));
if ( $mode == 'emailfrominvoice' ) $sendtobcc .= ( empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_INVOICE_TO ) ? '' : (( $sendtobcc ? " , " : " " ) . $conf -> global -> MAIN_MAIL_AUTOCOPY_INVOICE_TO ));
2016-06-24 16:10:52 +02:00
if ( $mode == 'emailfromsupplierproposal' ) $sendtobcc .= ( empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO ) ? '' : (( $sendtobcc ? " , " : " " ) . $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO ));
if ( $mode == 'emailfromsupplierorder' ) $sendtobcc .= ( empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO ) ? '' : (( $sendtobcc ? " , " : " " ) . $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO ));
if ( $mode == 'emailfromsupplierinvoice' ) $sendtobcc .= ( empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO ) ? '' : (( $sendtobcc ? " , " : " " ) . $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO ));
2013-09-23 13:17:31 +02:00
$deliveryreceipt = $_POST [ 'deliveryreceipt' ];
2013-09-25 21:36:40 +02:00
if ( $action == 'send' || $action == 'relance' )
2013-09-23 13:17:31 +02:00
{
if ( dol_strlen ( $_POST [ 'subject' ])) $subject = $_POST [ 'subject' ];
2016-10-24 02:02:30 +02:00
$actionmsg2 = $langs -> transnoentities ( 'MailSentBy' ) . ' ' . CMailFile :: getValidAddress ( $from , 4 , 0 , 1 ) . ' ' . $langs -> transnoentities ( 'To' ) . ' ' . CMailFile :: getValidAddress ( $sendto , 4 , 0 , 1 );
2013-09-23 13:17:31 +02:00
if ( $message )
{
2016-10-24 02:02:30 +02:00
$actionmsg = $langs -> transnoentities ( 'MailFrom' ) . ': ' . dol_escape_htmltag ( $from );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTo' ) . ': ' . dol_escape_htmltag ( $sendto ));
if ( $sendtocc ) $actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'Bcc' ) . " : " . dol_escape_htmltag ( $sendtocc ));
2014-11-18 19:03:02 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : " );
$actionmsg = dol_concatdesc ( $actionmsg , $message );
2013-09-23 13:17:31 +02:00
}
}
// Create form object
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
2016-06-24 16:10:52 +02:00
$formmail -> trackid = $trackid ; // $trackid must be defined
2013-09-23 13:17:31 +02:00
$attachedfiles = $formmail -> get_attached_files ();
$filepath = $attachedfiles [ 'paths' ];
$filename = $attachedfiles [ 'names' ];
$mimetype = $attachedfiles [ 'mimes' ];
2015-08-24 16:22:21 +02:00
2015-11-13 00:19:11 +01:00
// Feature to push mail sent into Sent folder
if ( ! empty ( $conf -> dolimail -> enabled ))
2015-08-24 16:05:15 +02:00
{
2015-11-13 00:19:11 +01:00
$mailfromid = explode ( " # " , $_POST [ 'frommail' ], 3 ); // $_POST['frommail'] = 'aaa#Sent# <aaa@aaa.com>' // TODO Use a better way to define Sent dir.
2015-08-26 15:04:50 +02:00
if ( count ( $mailfromid ) == 0 ) $from = $_POST [ 'fromname' ] . ' <' . $_POST [ 'frommail' ] . '>' ;
2015-08-24 16:05:15 +02:00
else
{
$mbid = $mailfromid [ 1 ];
2013-09-23 13:17:31 +02:00
2015-08-24 16:05:15 +02:00
/*IMAP Postbox*/
$mailboxconfig = new IMAP ( $db );
$mailboxconfig -> fetch ( $mbid );
if ( $mailboxconfig -> mailbox_imap_host ) $ref = $mailboxconfig -> get_ref ();
2016-09-20 12:19:17 +02:00
2015-08-24 16:05:15 +02:00
$mailboxconfig -> folder_id = $mailboxconfig -> mailbox_imap_outbox ;
$mailboxconfig -> userfolder_fetch ();
2016-09-20 12:19:17 +02:00
2015-08-24 16:05:15 +02:00
if ( $mailboxconfig -> mailbox_save_sent_mails == 1 )
{
2016-09-20 12:19:17 +02:00
2015-08-24 16:05:15 +02:00
$folder = str_replace ( $ref , '' , $mailboxconfig -> folder_cache_key );
2015-11-13 00:19:11 +01:00
if ( ! $folder ) $folder = " Sent " ; // Default Sent folder
2016-09-20 12:19:17 +02:00
2015-08-24 16:05:15 +02:00
$mailboxconfig -> mbox = imap_open ( $mailboxconfig -> get_connector_url () . $folder , $mailboxconfig -> mailbox_imap_login , $mailboxconfig -> mailbox_imap_password );
2016-09-20 12:19:17 +02:00
if ( FALSE === $mailboxconfig -> mbox )
2015-08-24 16:05:15 +02:00
{
$info = FALSE ;
$err = $langs -> trans ( 'Error3_Imap_Connection_Error' );
2015-11-19 13:59:58 +01:00
setEventMessages ( $err , $mailboxconfig -> element , null , 'errors' );
2016-09-20 12:19:17 +02:00
}
else
2015-08-24 16:05:15 +02:00
{
$mailboxconfig -> mailboxid = $_POST [ 'frommail' ];
$mailboxconfig -> foldername = $folder ;
$from = $mailfromid [ 0 ] . $mailfromid [ 2 ];
$imap = 1 ;
}
2016-09-20 12:19:17 +02:00
}
2015-08-24 16:05:15 +02:00
}
}
2016-09-20 12:19:17 +02:00
2013-09-23 13:17:31 +02:00
// Send mail
2015-08-24 16:22:21 +02:00
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , $sendtobcc , $deliveryreceipt , - 1 , '' , '' , $trackid );
2013-09-23 13:17:31 +02:00
if ( $mailfile -> error )
{
2016-06-24 16:10:52 +02:00
setEventMessage ( $mailfile -> error , 'errors' );
$action = 'presend' ;
2013-09-23 13:17:31 +02:00
}
else
{
$result = $mailfile -> sendfile ();
if ( $result )
{
$error = 0 ;
2016-09-20 12:19:17 +02:00
2015-12-18 12:45:04 +01:00
// FIXME This must be moved into a trigger for action $trigger_name
2015-11-13 00:19:11 +01:00
if ( ! empty ( $conf -> dolimail -> enabled ))
2015-08-24 16:05:15 +02:00
{
2015-11-13 00:19:11 +01:00
$mid = ( GETPOST ( 'mid' , 'int' ) ? GETPOST ( 'mid' , 'int' ) : 0 ); // Original mail id is set ?
2015-08-24 16:05:15 +02:00
if ( $mid )
{
2015-11-13 00:19:11 +01:00
// set imap flag answered if it is an answered mail
2015-08-24 16:05:15 +02:00
$dolimail = new DoliMail ( $db );
$dolimail -> id = $mid ;
$res = $dolimail -> set_prop ( $user , 'answered' , 1 );
2016-09-20 12:19:17 +02:00
}
2015-08-24 16:05:15 +02:00
if ( $imap == 1 )
{
// write mail to IMAP Server
2016-09-20 12:19:17 +02:00
$movemail = $mailboxconfig -> putMail ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , $folder , $deliveryreceipt , $mailfile );
2015-11-21 05:20:08 +01:00
if ( $movemail ) setEventMessages ( $langs -> trans ( " MailMovedToImapFolder " , $folder ), null , 'mesgs' );
2016-09-20 12:19:17 +02:00
else setEventMessages ( $langs -> trans ( " MailMovedToImapFolder_Warning " , $folder ), null , 'warnings' );
2015-08-24 16:05:15 +02:00
}
}
2015-12-18 12:45:04 +01:00
2015-11-21 05:20:08 +01:00
// Initialisation of datas
2013-09-25 21:36:40 +02:00
$object -> socid = $sendtosocid ; // To link to a company
$object -> sendtoid = $sendtoid ; // To link to a contact/address
2013-09-23 13:17:31 +02:00
$object -> actiontypecode = $actiontypecode ;
$object -> actionmsg = $actionmsg ; // Long text
$object -> actionmsg2 = $actionmsg2 ; // Short text
2016-10-03 00:39:07 +02:00
$object -> trackid = $trackid ;
2013-09-23 13:17:31 +02:00
$object -> fk_element = $object -> id ;
$object -> elementtype = $object -> element ;
2015-11-21 05:20:08 +01:00
// Call of triggers
2013-09-23 13:17:31 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
2014-11-04 13:54:18 +01:00
$result = $interface -> run_triggers ( $trigger_name , $object , $user , $langs , $conf );
2013-09-23 13:17:31 +02:00
if ( $result < 0 ) {
2016-09-20 12:19:17 +02:00
$error ++ ; $errors = $interface -> errors ;
2013-09-23 13:17:31 +02:00
}
2015-11-21 05:20:08 +01:00
// End call of triggers
2013-09-23 13:17:31 +02:00
if ( $error )
{
dol_print_error ( $db );
}
else
{
// Redirect here
// This avoid sending mail twice if going out and then back to page
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $from , 2 ), $mailfile -> getValidAddress ( $sendto , 2 ));
2015-11-19 13:59:58 +01:00
setEventMessages ( $mesg , null , 'mesgs' );
2016-09-20 12:19:17 +02:00
if ( $conf -> dolimail -> enabled ) header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?' . ( $paramname ? $paramname : 'id' ) . '=' . $object -> id . '&' . ( $paramname2 ? $paramname2 : 'mid' ) . '=' . $parm2val );
else header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?' . ( $paramname ? $paramname : 'id' ) . '=' . $object -> id );
2013-09-23 13:17:31 +02:00
exit ;
}
}
else
{
$langs -> load ( " other " );
2015-08-24 16:05:15 +02:00
$mesg = '<div class="error">' ;
2013-09-23 13:17:31 +02:00
if ( $mailfile -> error )
{
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $from , $sendto );
$mesg .= '<br>' . $mailfile -> error ;
}
else
{
2015-08-24 16:05:15 +02:00
$mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' ;
2013-09-23 13:17:31 +02:00
}
2015-08-24 16:05:15 +02:00
$mesg .= '</div>' ;
2015-11-19 13:59:58 +01:00
setEventMessages ( $mesg , null , 'warnings' );
2013-09-23 13:17:31 +02:00
$action = 'presend' ;
}
}
}
else
{
$langs -> load ( " errors " );
2015-11-19 13:59:58 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " MailTo " )), null , 'warnings' );
2013-09-23 13:17:31 +02:00
dol_syslog ( 'Try to send email with no recipiend defined' , LOG_WARNING );
$action = 'presend' ;
}
}
else
{
$langs -> load ( " other " );
2015-11-19 13:59:58 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFailedToReadEntity' , $object -> element ), null , 'errors' );
2013-09-23 13:17:31 +02:00
dol_syslog ( 'Failed to read data of object id=' . $object -> id . ' element=' . $object -> element );
$action = 'presend' ;
}
}