IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MkFramework Discussion :

Fonction Mail où placer le code


Sujet :

MkFramework

  1. #1
    Candidat au Club
    Femme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Fonction Mail où placer le code
    Bonjour,

    Je cherche à savoir où placer le code pour l'envoi d'un mail.
    J'ai créé un formulaire. Je désirerai que les données saisies soient affichées dans un tableau dans la page contacts::list et également transmise par mail à l'adresse indiquée.

    Mon formulaire html

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    <?php 
    $oForm=new plugin_form($this->oContacts);
    $oForm->setMessage($this->tMessage);
    ?>
    <form action="" method="POST" >
     
    <table class="tb_new">
     
    	<tr>
    		<th>email</th>
    		<td><?php echo $oForm->getInputText('email') ?></td>
    	</tr>
     
    	<tr>
    		<th>nom</th>
    		<td><?php echo $oForm->getInputText('nom') ?></td>
    	</tr>
     
    	<tr>
    		<th>prenom</th>
    		<td><?php echo $oForm->getInputText('prenom') ?></td>
    	</tr>
     
    	<tr>
    		<th>sujet</th>
    		<td><?php echo $oForm->getInputText('sujet') ?></td>
    	</tr>
     
    	<tr>
    		<th>message</th>
    		<td><?php echo $oForm->getInputTextarea('message') ?></td>
    	</tr>
     
     
    	<tr>
    		<th></th>
    		<td>
    			<p>
    				<input type="submit" value="Ajouter" /> <a href="<?php echo $this->getLink('contacts::list')?>">Annuler</a>
    			</p>
    		</td>
    	</tr>
    </table>
     
    <?php echo $oForm->getToken('token',$this->token)?>
     
    </form>
    Le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
     
    <?php 
    class module_contacts extends abstract_module{
     
    	public function before(){
    		$this->oLayout=new _layout('template1');
     
    		//$this->oLayout->addModule('menu','menu::index');
    	}
     
     
    	public function _index(){
    	    //on considere que la page par defaut est la page de listage
    	    $this->_list();
    	}
     
     
    	public function _list(){
     
    		$tContacts=model_contacts::getInstance()->findAll();
     
    		$oView=new _view('contacts::list');
    		$oView->tContacts=$tContacts;
     
     
     
    		$this->oLayout->add('main',$oView);
     
    	}
     
     
     
    	public function _new(){
    		$tMessage=$this->processSave();
     
    		$oContacts=new row_contacts;
     
    		$oView=new _view('contacts::new');
    		$oView->oContacts=$oContacts;
     
     
     
    		$oPluginXsrf=new plugin_xsrf();
    		$oView->token=$oPluginXsrf->getToken();
    		$oView->tMessage=$tMessage;
     
     
    		$this->oLayout->add('main',$oView);
    		$this->oLayout->title="nous contacter";
     
    	}
     
     
     
    	public function _edit(){
    		$tMessage=$this->processSave();
     
    		$oContacts=model_contacts::getInstance()->findById( _root::getParam('id') );
     
    		$oView=new _view('contacts::edit');
    		$oView->oContacts=$oContacts;
    		$oView->tId=model_contacts::getInstance()->getIdTab();
     
     
     
    		$oPluginXsrf=new plugin_xsrf();
    		$oView->token=$oPluginXsrf->getToken();
    		$oView->tMessage=$tMessage;
     
    		$this->oLayout->add('main',$oView);
    	}
     
     
     
    	public function _show(){
    		$oContacts=model_contacts::getInstance()->findById( _root::getParam('id') );
     
    		$oView=new _view('contacts::show');
    		$oView->oContacts=$oContacts;
     
     
     
    		$this->oLayout->add('main',$oView);
    	}
     
     
     
    	public function _delete(){
    		$tMessage=$this->processDelete();
     
    		$oContacts=model_contacts::getInstance()->findById( _root::getParam('id') );
     
    		$oView=new _view('contacts::delete');
    		$oView->oContacts=$oContacts;
     
     
     
    		$oPluginXsrf=new plugin_xsrf();
    		$oView->token=$oPluginXsrf->getToken();
    		$oView->tMessage=$tMessage;
     
    		$this->oLayout->add('main',$oView);
    	}
     
     
     
    	private function processSave(){
    		if(!_root::getRequest()->isPost() ){ //si ce n'est pas une requete POST on ne soumet pas
    			return null;
    		}
     
    		$oPluginXsrf=new plugin_xsrf();
    		if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide
    			return array('token'=>$oPluginXsrf->getMessage() );
    		}
     
     
    		$sFromEmail=_root::getParam('email');
    		$sFromIdentite=_root::getParam('nom').' '._root::getParam('prenom');
    		$sSubject=_root::getParam('sujet');
    		$sBody=_root::getParam('message');
    		$EmailDestinataire='adressedestinataire@mail.fr';
     
    		$oPluginMail=new plugin_mail();
     
    		$oPluginMail->setFrom($sFromIdentite,$sFromEmail);
     
    		$oPluginMail->addTo($EmailDestinataire);
     
    		$oPluginMail->setSubject( $sSubject );
    		$oPluginMail->setBodyHtml( $sBody );
     
    		if($oPluginMail->send()){
    			print "Email envoye : ok";
    			_root::redirect('contacts::list');
     
    			exit;
    		}
     
     
    		$iId=_root::getParam('id',null);
    		if($iId==null){
    			$oContacts=new row_contacts;	
    		}else{
    			$oContacts=model_contacts::getInstance()->findById( _root::getParam('id',null) );
    		}
     
    		$tColumn=array('email','nom','prenom','sujet','message');
    		foreach($tColumn as $sColumn){
    			$oContacts->$sColumn=_root::getParam($sColumn,null) ;
    		}
     
     
    		if($oContacts->save()){
    			//une fois enregistre on redirige (vers la page liste)
    			_root::redirect('contacts::list');
    		}else{
    			return $oContacts->getListError();
    		}
     
     
     
    	}
     
     
    	public function processDelete(){
    		if(!_root::getRequest()->isPost() ){ //si ce n'est pas une requete POST on ne soumet pas
    			return null;
    		}
     
    		$oPluginXsrf=new plugin_xsrf();
    		if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide
    			return array('token'=>$oPluginXsrf->getMessage() );
    		}
     
    		$oContacts=model_contacts::getInstance()->findById( _root::getParam('id',null) );
     
    		$oContacts->delete();
    		//une fois enregistre on redirige (vers la page liste)
    		_root::redirect('contacts::list');
     
    	}
     
     
    	public function after(){
    		$this->oLayout->show();
    	}
     
     
     
    }

    Merci pour votre aide

  2. #2
    Rédacteur
    Avatar de imikado
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    5 239
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2006
    Messages : 5 239
    Points : 19 100
    Points
    19 100
    Billets dans le blog
    17
    Par défaut
    Vous pouvez remplacer votre code d'envoi de mail par
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    if($oPluginMail->send()){
     
     
     
    			$iId=_root::getParam('id',null);
    			if($iId==null){
    				$oContacts=new row_contacts;	
    			}else{
    				$oContacts=model_contacts::getInstance()->findById( _root::getParam('id',null) );
    			}
     
    			$tColumn=array('email','nom','prenom','sujet','message');
    			foreach($tColumn as $sColumn){
    				$oContacts->$sColumn=_root::getParam($sColumn,null) ;
    			}
     
     
    			if($oContacts->save()){
    				//une fois enregistre on redirige (vers la page liste)
    				print "Email envoye : ok";
    				_root::redirect('contacts::list');
     
    				exit;
    			}else{
    				return $oContacts->getListError();
    			}
     
     
     
     
     
    		}
    Framework php sécurisé et simple à prendre en main avec générateur web http://mkframework.com/ (hebergé sur developpez.com)
    Mes cours/tutoriaux

  3. #3
    Candidat au Club
    Femme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Merci bcp ; cela fonctionne.

    Bonne journée

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. fonction mail activé ou non, ou c'est mon code ?
    Par halimux dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 19/01/2011, 16h09
  2. [FLASH MX] Problème flash et fonction mail() php
    Par proutcore dans le forum Flash
    Réponses: 7
    Dernier message: 21/05/2007, 12h21
  3. Fonction mail avec HTML et images
    Par nico33307 dans le forum Modules
    Réponses: 1
    Dernier message: 05/07/2005, 23h25
  4. [MFC](encapsulation ADO) ou placer le code
    Par philippe V dans le forum MFC
    Réponses: 2
    Dernier message: 13/06/2002, 14h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo