Hi Fabrice,
First of all, a lot of thanks again for your help.
I tell you, with images, the sequence I execute.
1. from a button in a cellule (attached code cellule) I call the
procedure Mail_convidats (attached code Mail_convidats).
----------------------------- code cellule
-------------------------------------
// Se valida email de reenvio
SI Length(NoSpace(Cellule_Mail.SAI_Mail_Reenvi)) >= 0 ALORS
w_OK_mail=Faux
w_OK_mail=ComprovarEmail(Cellule_Mail.SAI_Mail_Reenvi)
SI w_OK_mail=Faux ALORS
wVariable=Cellule_Mail.SAI_Mail_Reenvi..Libellé
Erreur(wVariable," "+"El mail ha d'estar informat i amb
format correcte.")
RETURN
FIN
FIN
reloj_arena..Visible=False
HLitRecherche(USER,USR_IDUSER,Cellule_Mail.Cellule_USR_IDUSER)
SI HTrouve()=Vrai ALORS
w_Parm_Pro = EnDecryp("D",USER.USR_PSW)
reloj_arena..Visible=Vrai
Mail_convidats(Cellule_Mail.Cellule_USR_IDUSER,w_Parm_Pro,wContracte,Cellule_Mail.SAI_Mail_Reenvi)
FIN
reloj_arena..Visible=Faux
// reloj_arena..Etat=Inactif
SBC_SLR001..Visible=Vrai
Cellule_Mail..Visible=Faux
--------------------------- Mail_convidats --------------------------------
PROCEDURE Mail_convidats(wUsuari,wPsw,wContrac,wTarget)
wRetorn is boolean
wAssumpte is a string
WCos is a string wCos1 is a string wCadena is a string
wMeupsw is a string
wDirectori is string
wMeupsw = EnDecryp("D",PARAM.EMP_PSW)
// ----------------- munta el cos del mail -----------------------
HReadSeek(CONTRACTES,CON_IDCONTRACTE,wContrac)
HReadSeek(SUBCON,USR_IDUSER,wUsuari)
wAssumpte = "Accés a l'aplicació CAE"
wCos1 = PARAM.EMP_POB + " , " +
DateVersChaîne(DateSys(),"JJ-MM-AAAA") + CR + CR + ...
"Benvolguts senyors," + CR + CR + ...
"Com a empresa participant al contracte esmentat a continuació:
" + CR + CR + " Obra : " +
CONTRACTES.CON_DESCRIPCIO + CR + ...
" Població : " + CONTRACTES.CON_POBOBR + CR +
CR + "i per tal de que puguin accedir a cumplimentar la informació
relativa a la seva empresa," + CR + ...
"els hi subministrem la informació adient." + CR + CR + ...
" URL : " + PARAM.EMP_URL + CR + ...
" Usuari : " + wUsuari + CR + ...
" Contrasenya : " + wPsw + CR + CR + ...
"Atentament," + CR + PARAM.EMP_NOM
wCadena = "mailsender=" + PARAM.EMP_CORREU + ...
"&nomsender=" + PARAM.EMP_NOM + ...
"&Psw=" + wMeupsw + ...
"&Server=" + PARAM.EMP_SMTP + ...
"&Port=" + PARAM.EMP_PORT + ...
"&Desti=" + SUBCON.SBC_NOMCOM + ...
"&Recip=" + wTarget + ...
"&Subject=" + wAssumpte + ...
"&Msg=" + wCos1
// comprova existencia script
wDirectori = fCurrentDir()
PHPDisplay("
http://www.cae171.com/L45/enviar-mailer.php",wCadena)
//
EnviarCorreu(PARAM.EMP_CORREU,wMeupsw,PARAM.EMP_SMTP,PARAM.EMP_PORT, + ...
// SUBCON.SBC_NOMCOM,wTarget,wAssumpte,WCos1)
RETOUR
2. In Mail_convidats procedure I set all the variables I need and call
via PHPDisplay() the script enviar-mailer.php (see below)
----------------------------------------- enviar-mailer.php
----------------------------
<?php
$mailsender = $_GET['mailsender']; // mail empresa CAE
$nomsender = $_GET['nomsender']; // Nom empresa CAE
$Psw = $_GET['Psw']; // Psw
$Server = $_GET['Server']; //servidor
$Port = $_GET['Port']; // Port
$nomrecip = $_GET['nomrecip']; // Nom desti a qui
s'envia el mail
$mailrecip = $_GET['mailrecip']; // @ del destinatari
$subject = $_GET['Subject']; // Assumpte
$msg = $_GET['Msg']; // Cos del missatge
echo $Server;
// require("includes/class.phpmailer.php");
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->From = $mailsender;
$mail->FromName = nomsender;
$mail->AddAddress($mailrecip); // Direccion de correo del cliente
// Aqui van los datos que apareceran en el correo que reciba
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
// Datos del servidor SMTP
$mail->IsSMTP();
$mail->SMTPSecure = "tls";
$mail->Host = $Server; // Servidor de Salida.
$mail->Port = $Port;
$mail->SMTPAuth = true;
$mail->Username = $mailsender; // Correo Electronico
$mail->Password = $Psw; // Contrasena
if ($mail->Send()){
echo "<script>alert('Correu enviat correctament');location.href
='javascript:history.back()';</script>";
}
else {
echo $mail->ErrorInfo;
echo "<script>alert('Error al enviar el formulari');location.href
='javascript:history.back()';</script>";
}
?>
The echo "Hola"; doen not appears, so I guess tha the script in not
execeuted. Any email is sent.
------------------------------------ conclusion --------------------------
All I need is to send a mail via SMTP.
Another trial I did is with the code
PROCEDURE
EnviarCorreu(wNomUser,wPswUser,wServerSMTP,wPort,wDesti,wRecip,wSubject,wMissatge)
//EmailStartSMTPSession(wNomUser,
wPswUser,wServerSMTP,wPort,False,emailOptionSécuriséTLS)
//EmailStartSession(gSessionSMTP)
EmailReset()
// Sender of the message
Email.Expéditeur = wNomUser
Email.NbDestinataire = 1
Email.Destinataire[1] = wRecip Email.Cc = PARAM.EMP_CC //
eliminar quan funcioni
// Subject and content of the message
Email.Subject = wSubject
Email.Message = wMissatge
//mail("aaa@bbb.es","Asunto","Este es el cuerpo del asunto")
IF EmailEnvoieMessage() = False THEN
Error(ErrorInfo())
END
// Close the SMTP session
//EmailCloseSession(wNomUser)
//fDelete("EmailContent.txt")
but I get an error in EmailEnvoieMessage() sentence because a parameter
is expected but I do not which parameter is. The help from Pcsoft for
this sentence does not include any parameter.
From your experience, which is the best way in order to send an email
from my application?
Method 1 with PHPDisplay() or method 2 with EmailEnvoieMessage() ?
Again, thanks for your help.