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

Langage PHP Discussion :

Envoie d'un formulaire par mail en PHP


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut Envoie d'un formulaire par mail en PHP
    Bonjour à tous,

    Je suis un webmaster débutant en PHP et je suis en train de monter un site internet où il me faut un formulaire de contact en PHP. J'ai réussi à trouver sur Internet la structure du formulaire en PHP mais je ne sais pas comment compléter le fichier pour qu'il soit opérationnel.

    Cela ressemble à ça :

    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
    <?php
    	$owner_email='email@email';
    	//SMTP server settings	
    	$host = '';
        $port = '465';//"587";
        $username = '';
        $password = '';
     
        $subject='[Site]Nouveau Message ';
        $user_email='';    
    	$message_body='';
    	$message_type='html';
     
    	$max_file_size=50;//MB 
    	$file_types='/(doc|docx|txt|pdf|zip|rar)$/';
    	$error_text='Il y a un problème';
    	$error_text_filesize='File size must be less than';
    	$error_text_filetype='Le format de fichier ne peut pas être uploadé. Voici les fichiers acceptés: doc, docx, txt, pdf, zip, rar.';
     
    	$private_recaptcha_key='6LeZwukSAAAAACmqrbLmdpvdhC68NLB1c9EA5vzU'; //localhost
     
     
    	$use_recaptcha=isset( $_POST["recaptcha_challenge_field"]) and isset($_POST["recaptcha_response_field"]);
    	$use_smtp=($host=='' or $username=='' or $password=='');
    	$max_file_size*=1048576;
     
    	if($owner_email==''){
    		die('Attention, recipient e-mail is not set! Please define "owner_email" variable in the MailHanlder.php file.');
    	}
     
    	if(preg_match('/^(127\.|192\.168\.)/',$_SERVER['REMOTE_ADDR'])){
    		die('Attention, contact form will not work locally! Please upload your template to a live hosting server.');
    	}
     
    	if($use_recaptcha){
    		require_once('recaptchalib.php');
    		$resp = recaptcha_check_answer ($private_recaptcha_key,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
    		if (!$resp->is_valid){
    			die ('wrong captcha');
    		}
    	}
     
    	if(isset($_POST['name']) and $_POST['name'] != ''){$message_body .= '<p>Visitor: ' . $_POST['name'] . '</p>' . "\n" . '<br>' . "\n"; $subject.=$_POST['name'];}
    	if(isset($_POST['email']) and $_POST['email'] != ''){$message_body .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n" . '<br>' . "\n"; $user_email=$_POST['email'];}
    	if(isset($_POST['state']) and $_POST['state'] != ''){$message_body .= '<p>State: ' . $_POST['state'] . '</p>' . "\n" . '<br>' . "\n";}
    	if(isset($_POST['phone']) and $_POST['phone'] != ''){$message_body .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n" . '<br>' . "\n";}	
    	if(isset($_POST['fax']) and $_POST['fax'] != ''){$message_body .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n" . '<br>' . "\n";}
    	if(isset($_POST['message']) and $_POST['message'] != ''){$message_body .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";}	
    	if(isset($_POST['stripHTML']) and $_POST['stripHTML']=='true'){$message_body = strip_tags($message_body);$message_type='text';}
     
    try{
    	include "libmail.php";
    	$m= new Mail("utf-8");
    	$m->From($user_email);
    	$m->To($owner_email);
    	$m->Subject($subject);
    	$m->Body($message_body,$message_type);
    	//$m->log_on(true);
     
    	if(isset($_FILES['attachment'])){
    		if($_FILES['attachment']['size']>$max_file_size){
    			$error_text=$error_text_filesize . ' ' . $max_file_size . 'bytes';
    			die($error_text);			
    		}else{			
    			if(preg_match($file_types,$_FILES['attachment']['name'])){
    				$m->Attach($_FILES['attachment']['tmp_name'],$_FILES['attachment']['name'],'','attachment');
    			}else{
    				$error_text=$error_text_filetype;
    				die($error_text);				
    			}
    		}		
    	}
    	if(!$use_smtp){
    		$m->smtp_on( $host, $username, $password, $port);
    	}
     
    	if($m->Send()){
    		die('success');
    	}	
     
    }catch(Exception $mail){
    	die($mail);
    }	
    ?>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Qu'obtiens-tu avec ce code ? Qu'est ce qui ne fonctionne pas ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut
    Bonsoir, j'obtiens ça quand je remplis le formulaire HTML :

    Parse error: syntax error, unexpected '{' in /mnt/162/sdb/c/3/alixe.peintures/mail/MailHandler.php on line 51
    J'imagine que je dois compléter les variables "owner_email", "port", "username" et "password" pour que cela fonctionne sur mon serveur de messagerie, mais dois-je changer autre chose ?

  4. #4
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut
    Il y a deux autres fichiers PHP qui sont utilisés pour le formulaire.
    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
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    <?php
    class Mail
    {
        private $charset = "UTF-8";
        private $boundary = "";
        private $SubBody = array();
        private $body = array();
        private $ctencoding = "base64";
        private $count_body = 1;
        private $checkAddress = true;
        private $headers = array();
        private $ready_headers = array();
        private $names_email = array();
        private $receipt = 0;
        private $smtpsendto = array();
        private $sendto = array();
        private $acc = array();
        private $abcc = array();
        private $smtp = array();
        private $smtp_log = '';
        private $log_on = false;
        private $body_header = array();
        public $status_mail = array('status' => true, "message" => 'ок');
        public function __construct($charset = "", $ctencoding = '')
        {
            $this->boundary = md5(uniqid("myboundary"));
            $this->smtp['on'] = false;
            if (strlen($ctencoding) and $ctencoding == '8bit')
            {
                $this->ctencoding = '8bit';
            }
            if (strlen($charset))
            {
                $this->charset = strtolower($charset);
                if ($this->charset == "us-ascii")
                {
                    $this->ctencoding = "7bit";
                }
            }
        }
        public function Body($text, $text_html = "", $alternative_text = '', $resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
            if ($text_html == "html")
                $text_html = "text/html";
            else
                $text_html = "text/plain";
            if ($this->ctencoding == 'base64')
            {
                if (strlen($alternative_text))
                    $alternative_text = chunk_split(base64_encode($alternative_text));
                if (strlen($text))
                    $text = chunk_split(base64_encode($text));
            }
            if (!strlen($alternative_text))
            {
                $body = "Content-Type: ".$text_html."; charset=".$this->charset."\r\n";
                $body.="Content-Transfer-Encoding: ".$this->ctencoding."\r\n\r\n";
                $body.=$text;
            }
            elseif (strlen($alternative_text) and $text_html == 'text/html')
            {
                $body = "Content-Type: multipart/alternative; boundary=ALT-".$this->boundary."\r\n\r\n";
                $body.="--ALT-".$this->boundary."\r\n";
                $body.="Content-Type: text/plain; charset=".$this->charset."\r\n";
                $body.="Content-Transfer-Encoding: ".$this->ctencoding."\r\n\r\n";
                $body.=$alternative_text."\r\n";
                $body.="--ALT-".$this->boundary."\r\n";
                $body.="Content-Type: text/html; charset=".$this->charset."\r\n";
                $body.="Content-Transfer-Encoding: ".$this->ctencoding."\r\n\r\n";
                $body.=$text."\r\n";
                $body.="--ALT-".$this->boundary."--";
            }
            $this->SubBody[$resource]['body'][0] = $body;
        }
        protected function mime_content_type($file)
        {
            $ext = strtolower(substr(strrchr(basename($file), '.'), 1));
            switch ($ext)
            {
                case 'jpg': return 'image/jpeg';
                case 'jpeg': return 'image/jpeg';
                case 'gif': return 'image/gif';
                case 'png': return 'image/png';
                case 'ico': return 'image/x-icon';
                case 'txt': return 'text/plain';
     
                default: return 'application/octet-stream';
            }
        }
     
        public function Attach($filename, $new_name_filename = "", $filetype = "", $disposition = "", $resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
            if (!file_exists($filename))
            {
                return FALSE;
            }
            if (strlen($new_name_filename))
                $basename = basename($new_name_filename);
            else
                $basename = basename($filename);
     
            $charset_name = "=?".$this->charset."?B?".base64_encode($basename)."?=";
            if (!strlen($filetype))
                $filetype = $this->mime_content_type($basename);
            $body = "Content-Type: ".$filetype."; name=\"$charset_name\"\r\n";
            $body.="Content-Transfer-Encoding: base64\r\n";
            if ($disposition == 'attachment')
            {
                $body.="Content-Disposition: attachment; filename=\"$charset_name\"\r\n";
            }
            $body.="Content-ID: <".$basename.">\r\n";
            $body.="\r\n";
            $body.=chunk_split(base64_encode(file_get_contents($filename)));
            if ($disposition == 'attachment')
                $this->SubBody[$resource]['mixed'][] = $body;
            else
            {
                $this->SubBody[$resource]['body'][$this->count_body] = $body;
                $this->count_body++;
            }
        }
        public function BuildMail($resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
            $this->ready_headers[$resource] = '';        
            if (isset($this->SubBody[$resource]['body']))
                $resource_body = $resource;
            else
                $resource_body = 'webi';
            if (!is_array($this->sendto[$resource]) OR !count($this->sendto[$resource]))
            {
                $this->status_mail['status'] = false;
                $this->status_mail['message'] = "Error : no recipient selected for ".$resource;
                // return false;
            }
            if (!isset($this->body[$resource_body]))
            {
                if (count($this->SubBody[$resource_body]['body']) > 1)
                {
                    $body = implode("\r\n--REL-".$this->boundary."\r\n", $this->SubBody[$resource_body]['body']);
                    $body = "Content-Type: multipart/related; boundary=REL-".$this->boundary."\r\n\r\n"
                            .'--REL-'.$this->boundary."\r\n".$body.'--REL-'.$this->boundary."--";
                }
                else
                {
                    $body = $this->SubBody[$resource_body]['body'][0];
                }
                if (isset($this->SubBody[$resource_body]['mixed']) AND count($this->SubBody[$resource_body]['mixed']))
                {
                    $bodymix = implode('--MIX-'.$this->boundary."\r\n", $this->SubBody[$resource_body]['mixed']);
                    $body = $body."\r\n--MIX-".$this->boundary."\r\n".$bodymix;
                    $body = "Content-Type: multipart/mixed; boundary=MIX-".$this->boundary."\r\n\r\n"
                            .'--MIX-'.$this->boundary."\r\n".$body.'--MIX-'.$this->boundary."--";
                }
                unset($this->SubBody[$resource_body]);
                $temp_mass = explode("\r\n\r\n", $body);
                $this->body_header[$resource_body] = $temp_mass[0];
                unset($temp_mass[0]);
                $this->body[$resource_body] = implode("\r\n\r\n", $temp_mass);
                unset($temp_mass);
                unset($body);
            }
            $temp_mass = array();
            foreach ($this->sendto[$resource] as $key => $value)
            {
     
                if (strlen($this->names_email[$resource]['To'][$value]))
                    $temp_mass[] = "=?".$this->charset."?Q?".str_replace("+", "_", str_replace("%", "=", urlencode(strtr($this->names_email[$resource]['To'][$value], "\r\n", "  "))))."?= <".$value.">";
                else
                    $temp_mass[] = $value;
            }
            $this->headers[$resource]['To'] = implode(", ", $temp_mass);
            if (isset($this->acc[$resource]) and count($this->acc[$resource]) > 0)
                $this->headers[$resource]['CC'] = implode(", ", $this->acc[$resource]);
            if (isset($this->abcc[$resource]) and count($this->abcc[$resource]) > 0)
                $this->headers[$resource]['BCC'] = implode(", ", $this->abcc[$resource]);
            if ($this->receipt)
            {
                if (isset($this->headers["Reply-To"]))
                    $this->headers["Disposition-Notification-To"] = $this->headers["Reply-To"];
                else
                    $this->headers["Disposition-Notification-To"] = $this->headers['From'];
            }
            if ($this->charset != "")
            {
                $this->headers["Mime-Version"] = "1.0";
            }
            $this->headers["X-Mailer"] = "Php_libMail_v_2.0(webi.ru)";
            if (!isset($this->headers[$resource]['Subject']) and isset($this->headers['webi']['Subject']))
                $this->headers[$resource]['Subject'] = $this->headers['webi']['Subject'];
            if ($this->smtp['on'])
            {
                $user_domen = explode('@', $this->headers['From']);
                $this->ready_headers[$resource] .= "Date: ".date("r")."\r\n";
                $this->ready_headers[$resource] .= "Message-ID: <".rand().".".$resource.date("YmjHis")."@".$user_domen[1].">\r\n";
                foreach ($this->headers[$resource] as $key => $value)
                {
                    $new_mass_head[$key] = $value;
                }            
                foreach ($this->headers as $key => $value)
                {
                    if (!is_array($value))
                        $new_mass_head[$key] = $value;
                }
                reset($new_mass_head);
                while (list( $hdr, $value ) = each($new_mass_head))
                {
                    if ($hdr == "From" and strlen($this->names_email['from']))
                        $this->ready_headers[$resource] .= $hdr.": =?".$this->charset."?Q?".str_replace("+", "_", str_replace("%", "=", urlencode(strtr($this->names_email['from'], "\r\n", "  "))))."?= <".$value.">\r\n";
                    elseif ($hdr == "Reply-To" and strlen($this->names_email['Reply-To']))
                        $this->ready_headers[$resource] .= $hdr.": =?".$this->charset."?Q?".str_replace("+", "_", str_replace("%", "=", urlencode(strtr($this->names_email['Reply-To'], "\r\n", "  "))))."?= <".$value.">\r\n";
                    elseif ($hdr != "BCC")
                        $this->ready_headers[$resource] .= $hdr.": ".$value."\r\n";
                }
            }
            else
            {
                foreach ($this->headers[$resource] as $key => $value)
                {
                    $new_mass_head[$key] = $value;
                }
                foreach ($this->headers as $key => $value)
                {
                    if (!is_array($value))
                        $new_mass_head[$key] = $value;
                }
                reset($new_mass_head);
                while (list( $hdr, $value ) = each($new_mass_head))
                {
                    if ($hdr == "From" and strlen($this->names_email['from']))
                        $this->ready_headers[$resource] .= $hdr.": =?".$this->charset."?Q?".str_replace("+", "_", str_replace("%", "=", urlencode(strtr($this->names_email['from'], "\r\n", "  "))))."?= <".$value.">\r\n";
                    elseif ($hdr == "Reply-To" and strlen($this->names_email['Reply-To']))
                        $this->ready_headers[$resource] .= $hdr.": =?".$this->charset."?Q?".str_replace("+", "_", str_replace("%", "=", urlencode(strtr($this->names_email['Reply-To'], "\r\n", "  "))))."?= <".$value.">\r\n";
                    elseif ($hdr != "Subject" and $hdr != "To")
                        $this->ready_headers[$resource] .= "$hdr: $value\r\n";
                }
            }
            $this->ready_headers[$resource].=$this->body_header[$resource_body]."\r\n";
        }
        public function autoCheck($bool)
        {
            if ($bool)
                $this->checkAddress = true;
            else
                $this->checkAddress = false;
        }
        public function log_on($bool)
        {
            if ($bool)
                $this->log_on = true;
            else
                $this->log_on = false;
        }
        public function Subject($subject, $resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
            $this->headers[$resource]['Subject'] = "=?".$this->charset."?Q?".str_replace("+", "_", str_replace("%", "=", urlencode(strtr($subject, "\r\n", "  "))))."?=";
        }
        public function From($from)
        {
            if (!is_string($from))
            {
                $this->status_mail['status'] = false;
                $this->status_mail['message'] = "Error, From should be inline";
                return FALSE;
            }
            $temp_mass = explode(';', $from);
            if (count($temp_mass) == 2)
            {
                $this->names_email['from'] = $temp_mass[0];
                $this->headers['From'] = $temp_mass[1];
            }
            else
            {
                $this->names_email['from'] = '';
                $this->headers['From'] = $from;
            }
        }
        public function ReplyTo($address)
        {
            if (!is_string($address))
                return false;
            $temp_mass = explode(';', $address);
            if (count($temp_mass) == 2)
            {
                $this->names_email['Reply-To'] = $temp_mass[0];
                $this->headers['Reply-To'] = $temp_mass[1];
            }
            else
            {
                $this->names_email['Reply-To'] = '';
                $this->headers['Reply-To'] = $address;
            }
        }
        public function Receipt()
        {
            $this->receipt = 1;
        }
        public function To($to, $resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
            if (is_array($to))
            {
                foreach ($to as $key => $value)
                {
                    $temp_mass = explode(';', $value);
                    if (count($temp_mass) == 2)
                    {
                        $this->smtpsendto[$resource][$temp_mass[1]] = $temp_mass[1];
                        $this->names_email[$resource]['To'][$temp_mass[1]] = $temp_mass[0];
                        $this->sendto[$resource][] = $temp_mass[1];
                    }
                    else
                    {
                        $this->smtpsendto[$resource][$value] = $value;
                        $this->names_email[$resource]['To'][$value] = '';
                        $this->sendto[$resource][] = $value;
                    }
                }
            }
            else
            {
                $temp_mass = explode(';', $to);
                if (count($temp_mass) == 2)
                {
                    $this->sendto[$resource][] = $temp_mass[1];
                    $this->smtpsendto[$resource][$temp_mass[1]] = $temp_mass[1];
                    $this->names_email[$resource]['To'][$temp_mass[1]] = $temp_mass[0];
                }
                else
                {
                    $this->sendto[$resource][] = $to;
                    $this->smtpsendto[$resource][$to] = $to;
     
                    $this->names_email[$resource]['To'][$to] = '';
                }
            }
            if ($this->checkAddress == true)
                $this->CheckAdresses($this->sendto[$resource]);
        }
        private function CheckAdresses($aad)
        {
            foreach ($aad as $key => $value)
            {
                if (!$this->ValidEmail($value))
                {
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "Error : wrong email ".$value;
                    return FALSE;
                }
            }
        }
        public function ValidEmail($address)
        {
            if (function_exists('filter_list'))
            {
                $valid_email = filter_var($address, FILTER_VALIDATE_EMAIL);
                if ($valid_email !== false)
                    return true;
                else
                    return false;
            }
            else
            {
                if (ereg(".*<(.+)>", $address, $regs))
                {
                    $address = $regs[1];
                }
                if (ereg("^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $address))
                    return true;
                else
                    return false;
            }
        }
        public function Cc($cc, $resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
     
            if (is_array($cc))
            {
                foreach ($cc as $key => $value)
                {
                    $this->smtpsendto[$resource][$value] = $value;
                    $this->acc[$resource][$value] = $value;
                }
            }
            else
            {
                $this->acc[$resource][$cc] = $cc;
                $this->smtpsendto[$resource][$cc] = $cc;
            }
            if ($this->checkAddress == true)
                $this->CheckAdresses($this->acc[$resource]);
        }
        public function Bcc($bcc, $resource = 'webi')
        {
            if (!strlen($resource))
                $resource = 'webi';
            if (is_array($bcc))
            {
                foreach ($bcc as $key => $value)
                {
                    $this->smtpsendto[$resource][$value] = $value;
                    $this->abcc[$resource][$value] = $value;
                }
            }
            else
            {
                $this->abcc[$resource][$bcc] = $bcc;
                $this->smtpsendto[$resource][$bcc] = $bcc;
            }
            if ($this->checkAddress == true)
                $this->CheckAdresses($this->abcc[$resource]);
        }
        public function Organization($org)
        {
            if (trim($org != ""))
                $this->headers['Organization'] = $org;
        }
        public function Priority($priority)
        {
            $priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
            if (!intval($priority))
                return false;
     
            if (!isset($priorities[$priority - 1]))
                return false;
     
            $this->headers["X-Priority"] = $priorities[$priority - 1];
     
            return true;
        }
        public function smtp_on($smtp_serv, $login, $pass, $port = 25, $timeout = 5)
        {
            $this->smtp['on'] = true; // smtp transfer on
            $this->smtp['serv'] = $smtp_serv;
            $this->smtp['login'] = $login;
            $this->smtp['pass'] = $pass;
            $this->smtp['port'] = $port;
            $this->smtp['timeout'] = $timeout;
        }
        private function get_data($smtp_conn)
        {
            $data = "";
            while ($str = fgets($smtp_conn, 515))
            {
                $data .= $str;
                if (substr($str, 3, 1) == " ")
                {
                    break;
                }
            }
            return $data;
        }
        private function add_log($text)
        {
            if ($this->log_on)
                $this->smtp_log.=$text;
        }
        public function Send()
        {
            if (!$this->status_mail['status'])
            {
                return FALSE;
            }
            if (!$this->smtp['on'])
            {
                foreach ($this->sendto as $key => $value)
                {
                    $strTo = implode(", ", $this->sendto[$key]);
                    $this->BuildMail($key);
                    if (!$this->status_mail['status'])
                    {
                        return FALSE;
                    }
                    if (isset($this->body[$key]))
                        $body_resource = $key;
                    else
                        $body_resource = 'webi';
                    $res = @mail($strTo, $this->headers[$key]['Subject'], $this->body[$body_resource], $this->ready_headers[$key]);
                    if (!$res)
                    {
                        $this->status_mail['status'] = false;
                        $this->status_mail['message'] = "Error : mail() function returns error";
                    }
                    elseif ($this->status_mail['status'])
                    {
                        $this->add_log('TO: '.$strTo."\n");
                        $this->add_log("Subject: ".$this->headers[$key]['Subject']."\n");
                        $this->add_log($this->ready_headers[$key]."\n\n");
                        $this->add_log($this->body[$body_resource]."\n\n\n");
                        $this->status_mail['status'] = true;
                        $this->status_mail['message'] = "Message successfully sent by mail()";
                    }
                    if ($key != 'webi')
                    {
                        unset($this->headers[$key]);
                        unset($this->ready_headers[$key]);
                    }
                    if ($body_resource != 'webi')
                    {
                        unset($this->body[$body_resource]);
                    }
                }
                if ($this->status_mail['status'])
                {
                    return true;
                }
                else
                {
                    return FALSE;
                }
            }
            else
            {
                if (!$this->smtp['serv'] OR !$this->smtp['login'] OR !$this->smtp['pass'] OR !$this->smtp['port'])
                {
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "Error : missing required SMTP values ";
                    return false;
                }
                $user_domen = explode('@', $this->headers['From']);
                $smtp_conn = fsockopen($this->smtp['serv'], $this->smtp['port'], $errno, $errstr, $this->smtp['timeout']);
                if (!$smtp_conn)
                {
                    $this->add_log("can't connect to server\n\n");
                    fclose($smtp_conn);
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "Error: can't connect to server";
                    return false;
                }
                $data = $this->get_data($smtp_conn)."\n";
                $this->add_log($data);
                fputs($smtp_conn, "EHLO ".$user_domen[0]."\r\n");
                $this->add_log("I: EHLO ".$user_domen[0]."\n");
                $data = $this->get_data($smtp_conn)."\n";
                $this->add_log($data);
                $code = substr($data, 0, 3);
                if ($code != 250)
                {
                    $this->add_log("Error greeting EHLO \n");
                    fclose($smtp_conn);
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "Error: greeting EHLO";
                    return false;
                }
                fputs($smtp_conn, "AUTH LOGIN\r\n");
                $this->add_log( "I: AUTH LOGIN\n");
                $data = $this->get_data($smtp_conn)."\n";
                $this->add_log($data);
                $code = substr($data, 0, 3);
                if ($code != 334)
                {
                    $this->add_log("server denies authorization \n");
                    fclose($smtp_conn);
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "server denies authorization";
                    return false;
                }
                fputs($smtp_conn, base64_encode($this->smtp['login'])."\r\n");
                $this->add_log( "I: ".base64_encode($this->smtp['login'])."\n");
                $data = $this->get_data($smtp_conn)."\n";
                $this->add_log($data);
                $code = substr($data, 0, 3);
                if ($code != 334)
                {
                    $this->add_log( "user access failed\n");
                    fclose($smtp_conn);
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "user SMTP access failed ";
                    return false;
                }
                fputs($smtp_conn, base64_encode($this->smtp['pass'])."\r\n");
                $this->add_log("I: parol_skryt\n");
                $data = $this->get_data($smtp_conn)."\n";
                $this->add_log($data);
                $code = substr($data, 0, 3);
                if ($code != 235)
                {
                    $this->add_log("wrong password\n");
                    fclose($smtp_conn);
                    $this->status_mail['status'] = false;
                    $this->status_mail['message'] = "wrong password for SMTP";
                    return false;
                }
                foreach ($this->smtpsendto as $key_res => $value_res)
                {
                    $this->BuildMail($key_res);
                    if (!$this->status_mail['status'])
                    {
                        return FALSE;
                    }
                    if (isset($this->body[$key_res]))
                        $body_resource = $key_res;
                    else
                        $body_resource = 'webi';
                    fputs($smtp_conn, "MAIL FROM:<".$this->headers['From']."> SIZE=".strlen($this->ready_headers[$key_res]."\r\n".$this->body[$body_resource])."\r\n");
                    $this->add_log("I: MAIL FROM:<".$this->headers['From']."> SIZE=".strlen($this->ready_headers[$key_res]."\r\n".$this->body[$body_resource])."\n");
                    $data = $this->get_data($smtp_conn)."\n";
                    $this->add_log($data); 
                    $code = substr($data, 0, 3);
                    if ($code != 250)
                    {
                        $this->add_log("command MAIL FROM denied by server\n");
                        fclose($smtp_conn);
                        $this->status_mail['status'] = false;
                        $this->status_mail['message'] = "command MAIL FROM through SMTP denied by server ";
                        return false;
                    }
                    foreach ($this->smtpsendto[$key_res] as $keywebi => $valuewebi)
                    {
                        fputs($smtp_conn, "RCPT TO:<".$valuewebi.">\r\n");
                        $this->add_log("I: RCPT TO:<".$valuewebi.">\n");
                        $data = $this->get_data($smtp_conn)."\n";
                        $this->add_log($data);
                        $code = substr($data, 0, 3);
                        if ($code != 250 AND $code != 251)
                        {
                            $this->add_log( "Server denied RCPT TO command\n");
                            fclose($smtp_conn);
                            $this->status_mail['status'] = false;
                            $this->status_mail['message'] = "Server denied RCPT TO command through SMTP";
                            return false;
                        }
                    }
                    fputs($smtp_conn, "DATA\r\n");
                    $this->add_log("I: DATA\n");
                    $data = $this->get_data($smtp_conn)."\n";
                    $this->add_log($data);                
                    $code = substr($data, 0, 3);
                    if ($code != 354)
                    {
                        $this->add_log( "server denied DATA command \n");
                        fclose($smtp_conn);
                        $this->status_mail['status'] = false;
                        $this->status_mail['message'] = "server denied DATA command through SMTP";
                        return false;
                    }
                    fputs($smtp_conn, $this->ready_headers[$key_res]."\r\n".$this->body[$body_resource]."\r\n.\r\n");
                    $this->add_log("I: ".$this->ready_headers[$key_res]."\r\n".$this->body[$body_resource]."\r\n.\r\n");
                    $data = $this->get_data($smtp_conn)."\n";
                    $this->add_log($data);
                    $code = substr($data, 0, 3);
                    if ($code != 250)
                    {
                        $this->add_log("error sending message\n");
                        fclose($smtp_conn);
                        $this->status_mail['status'] = false;
                        $this->status_mail['message'] = "error sending message through SMTP";
                        return false;
                    }
                    fputs($smtp_conn, "RSET\r\n");
                    $this->add_log("I: RSET\n");
                    $data = $this->get_data($smtp_conn)."\n";
                    $this->add_log($data);
                    $code = substr($data, 0, 3);
                    if ($code != 250)
                    {
                        $this->add_log("error sending message\n");
                        fclose($smtp_conn);
                        $this->status_mail['status'] = false;
                        $this->status_mail['message'] = "Server denied RSET command";
                        return false;
                    }
                    if ($key_res != 'webi')
                    {
                        unset($this->headers[$key_res]);
                        unset($this->ready_headers[$key_res]);
                    }
                    if ($body_resource != 'webi')
                    {
                        unset($this->body[$body_resource]);
                    }
                }
                fputs($smtp_conn, "QUIT\r\n");
                $this->add_log("QUIT\r\n");
                $data = $this->get_data($smtp_conn)."\n";
                $this->add_log($data);
                fclose($smtp_conn);
                $this->status_mail['status'] = true;
                $this->status_mail['message'] = "Message successfully sent through SMTP";
                return true;
            }
        }
        public function Get()
        {
            if (!$this->log_on)
                return 'Logging disabled. To create log file enable logging setting $m->log_on(true);';
     
            if (strlen($this->smtp_log))
            {
                return $this->smtp_log;
            }
        }
    }
    ?>
    Et le second :
    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
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    <?php
    /*
     * This is a PHP library that handles calling reCAPTCHA.
     *    - Documentation and latest version
     *          http://recaptcha.net/plugins/php/
     *    - Get a reCAPTCHA API Key
     *          https://www.google.com/recaptcha/admin/create
     *    - Discussion group
     *          http://groups.google.com/group/recaptcha
     *
     * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
     * AUTHORS:
     *   Mike Crawford
     *   Ben Maurer
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     */
     
    /**
     * The reCAPTCHA server URL's
     */
    define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
    define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
    define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
     
    /**
     * Encodes the given data into a query string format
     * @param $data - array of string elements to be encoded
     * @return string - encoded request
     */
    function _recaptcha_qsencode ($data) {
            $req = "";
            foreach ( $data as $key => $value )
                    $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
     
            // Cut the last '&'
            $req=substr($req,0,strlen($req)-1);
            return $req;
    }
     
     
     
    /**
     * Submits an HTTP POST to a reCAPTCHA server
     * @param string $host
     * @param string $path
     * @param array $data
     * @param int port
     * @return array response
     */
    function _recaptcha_http_post($host, $path, $data, $port = 80) {
     
            $req = _recaptcha_qsencode ($data);
     
            $http_request  = "POST $path HTTP/1.0\r\n";
            $http_request .= "Host: $host\r\n";
            $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
            $http_request .= "Content-Length: " . strlen($req) . "\r\n";
            $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
            $http_request .= "\r\n";
            $http_request .= $req;
     
            $response = '';
            if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
                    die ('Could not open socket');
            }
     
            fwrite($fs, $http_request);
     
            while ( !feof($fs) )
                    $response .= fgets($fs, 1160); // One TCP-IP packet
            fclose($fs);
            $response = explode("\r\n\r\n", $response, 2);
     
            return $response;
    }
     
     
     
    /**
     * Gets the challenge HTML (javascript and non-javascript version).
     * This is called from the browser, and the resulting reCAPTCHA HTML widget
     * is embedded within the HTML form it was called from.
     * @param string $pubkey A public key for reCAPTCHA
     * @param string $error The error given by reCAPTCHA (optional, default is null)
     * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
    
     * @return string - The HTML to be embedded in the user's form.
     */
    function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
    {
    	if ($pubkey == null || $pubkey == '') {
    		die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
    	}
     
    	if ($use_ssl) {
                    $server = RECAPTCHA_API_SECURE_SERVER;
            } else {
                    $server = RECAPTCHA_API_SERVER;
            }
     
            $errorpart = "";
            if ($error) {
               $errorpart = "&amp;error=" . $error;
            }
            return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
    
    	<noscript>
      		<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
      		<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
      		<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    	</noscript>';
    }
     
     
     
     
    /**
     * A ReCaptchaResponse is returned from recaptcha_check_answer()
     */
    class ReCaptchaResponse {
            var $is_valid;
            var $error;
    }
     
     
    /**
      * Calls an HTTP POST function to verify if the user's guess was correct
      * @param string $privkey
      * @param string $remoteip
      * @param string $challenge
      * @param string $response
      * @param array $extra_params an array of extra variables to post to the server
      * @return ReCaptchaResponse
      */
    function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
    {
    	if ($privkey == null || $privkey == '') {
    		die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
    	}
     
    	if ($remoteip == null || $remoteip == '') {
    		die ("For security reasons, you must pass the remote ip to reCAPTCHA");
    	}
     
     
     
            //discard spam submissions
            if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
                    $recaptcha_response = new ReCaptchaResponse();
                    $recaptcha_response->is_valid = false;
                    $recaptcha_response->error = 'incorrect-captcha-sol';
                    return $recaptcha_response;
            }
     
            $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
                                              array (
                                                     'privatekey' => $privkey,
                                                     'remoteip' => $remoteip,
                                                     'challenge' => $challenge,
                                                     'response' => $response
                                                     ) + $extra_params
                                              );
     
            $answers = explode ("\n", $response [1]);
            $recaptcha_response = new ReCaptchaResponse();
     
            if (trim ($answers [0]) == 'true') {
                    $recaptcha_response->is_valid = true;
            }
            else {
                    $recaptcha_response->is_valid = false;
                    $recaptcha_response->error = $answers [1];
            }
            return $recaptcha_response;
     
    }
     
    /**
     * gets a URL where the user can sign up for reCAPTCHA. If your application
     * has a configuration page where you enter a key, you should provide a link
     * using this function.
     * @param string $domain The domain where the page is hosted
     * @param string $appname The name of your application
     */
    function recaptcha_get_signup_url ($domain = null, $appname = null) {
    	return "https://www.google.com/recaptcha/admin/create?" .  _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
    }
     
    function _recaptcha_aes_pad($val) {
    	$block_size = 16;
    	$numpad = $block_size - (strlen ($val) % $block_size);
    	return str_pad($val, strlen ($val) + $numpad, chr($numpad));
    }
     
    /* Mailhide related code */
     
    function _recaptcha_aes_encrypt($val,$ky) {
    	if (! function_exists ("mcrypt_encrypt")) {
    		die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
    	}
    	$mode=MCRYPT_MODE_CBC;   
    	$enc=MCRYPT_RIJNDAEL_128;
    	$val=_recaptcha_aes_pad($val);
    	return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
    }
     
     
    function _recaptcha_mailhide_urlbase64 ($x) {
    	return strtr(base64_encode ($x), '+/', '-_');
    }
     
    /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
    function recaptcha_mailhide_url($pubkey, $privkey, $email) {
    	if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
    		die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
    		     "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
    	}
     
     
    	$ky = pack('H*', $privkey);
    	$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
     
    	return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
    }
     
    /**
     * gets the parts of the email to expose to the user.
     * eg, given johndoe@example,com return ["john", "example.com"].
     * the email is then displayed as john...@example.com
     */
    function _recaptcha_mailhide_email_parts ($email) {
    	$arr = preg_split("/@/", $email );
     
    	if (strlen ($arr[0]) <= 4) {
    		$arr[0] = substr ($arr[0], 0, 1);
    	} else if (strlen ($arr[0]) <= 6) {
    		$arr[0] = substr ($arr[0], 0, 3);
    	} else {
    		$arr[0] = substr ($arr[0], 0, 4);
    	}
    	return $arr;
    }
     
    /**
     * Gets html to display an email address given a public an private key.
     * to get a key, go to:
     *
     * http://www.google.com/recaptcha/mailhide/apikey
     */
    function recaptcha_mailhide_html($pubkey, $privkey, $email) {
    	$emailparts = _recaptcha_mailhide_email_parts ($email);
    	$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
     
    	return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
    		"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
     
    }
     
     
    ?>

  5. #5
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    MailHandler.php c'est le code que tu as mis dans le premier message ?
    Si oui, assure toi que ton serveur est bien en PHP5.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  6. #6
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut
    MailHandler.php c'est le code que tu as mis dans le premier message ?
    Oui, c'est bien celui dans le premier message.


    Si oui, assure toi que ton serveur est bien en PHP5.
    Il s'agit d'un site hébergé chez free.

  7. #7
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut
    Mais en même temps, le fichier "MailHandler.php" est resté tel quel, je n'ai rien modifié. Je dois sûrement changer la valeur de certaines variables, mais je ne sais pas lesquelles. J'ai testé plusieurs scénarios et j'ai toujours une erreur au moment de l'envoie du formulaire (ligne 51). Cela doit venir des paramètres du serveur mail sur lequel est envoyé le formulaire, non ?

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Le fait qu'il soit resté tel quel n'en fait pas un code qui fonctionne.
    Bref chez free de mémoire c'est du PHP4, vérifie sur ton phpinfo().
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut
    Après avoir renseigné le serveur mail de free dans le fichier MailHandler.php j'obtient ça :

    Error!

    Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.free.fr:587 (Network is unreachable) in /mnt/162/sdb/c/3/alixe.peintures/mail/libmail.php on line 531

    Warning: fclose(): supplied argument is not a valid stream resource in /mnt/162/sdb/c/3/alixe.peintures/mail/libmail.php on line 535

  10. #10
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Octobre 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2014
    Messages : 36
    Points : 16
    Points
    16
    Par défaut
    Voici mon fichier Mailhander.php avec ce que j'ai mis actuellement. Je souhaite envoyer le formulaire sur une adresse mail free. Le serveur SMTP est bon normalement... Les erreurs aux lignes 531 et 535 du fichier "libmail.php" proviennent pourtant du serveur mail... A noter que le serveur est bien en PHP5 maintenant !

    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
    <?php
    	$owner_email='test@free.fr';
    	//SMTP server settings	
    	$host = 'smtp.free.fr';
        $port = '465';//"587";
        $username = 'test@free.fr';
        $password = '12345678';
     
        $subject='A message from your site visitor ';
        $user_email='';    
    	$message_body='';
    	$message_type='html';
     
    	$max_file_size=50;//MB 
    	$file_types='/(doc|docx|txt|pdf|zip|rar)$/';
    	$error_text='something goes wrong';
    	$error_text_filesize='File size must be less than';
    	$error_text_filetype='Failed to upload file. This file type is not allowed. Accepted files types: doc, docx, txt, pdf, zip, rar.';
     
    	$private_recaptcha_key='6LeZwukSAAAAACmqrbLmdpvdhC68NLB1c9EA5vzU'; //localhost
     
     
    	$use_recaptcha=isset( $_POST["recaptcha_challenge_field"]) and isset($_POST["recaptcha_response_field"]);
    	$use_smtp=($host=='' or $username=='' or $password=='');
    	$max_file_size*=1048576;
     
    	if($owner_email==''){
    		die('Attention, recipient e-mail is not set! Please define "owner_email" variable in the MailHanlder.php file.');
    	}
     
    	if(preg_match('/^(127\.|192\.168\.)/',$_SERVER['REMOTE_ADDR'])){
    		die('Attention, contact form will not work locally! Please upload your template to a live hosting server.');
    	}
     
    	if($use_recaptcha){
    		require_once('recaptchalib.php');
    		$resp = recaptcha_check_answer ($private_recaptcha_key,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
    		if (!$resp->is_valid){
    			die ('wrong captcha');
    		}
    	}
     
    	if(isset($_POST['name']) and $_POST['name'] != ''){$message_body .= '<p>Visitor: ' . $_POST['name'] . '</p>' . "\n" . '<br>' . "\n"; $subject.=$_POST['name'];}
    	if(isset($_POST['email']) and $_POST['email'] != ''){$message_body .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n" . '<br>' . "\n"; $user_email=$_POST['email'];}
    	if(isset($_POST['state']) and $_POST['state'] != ''){$message_body .= '<p>State: ' . $_POST['state'] . '</p>' . "\n" . '<br>' . "\n";}
    	if(isset($_POST['phone']) and $_POST['phone'] != ''){$message_body .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n" . '<br>' . "\n";}	
    	if(isset($_POST['fax']) and $_POST['fax'] != ''){$message_body .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n" . '<br>' . "\n";}
    	if(isset($_POST['message']) and $_POST['message'] != ''){$message_body .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";}	
    	if(isset($_POST['stripHTML']) and $_POST['stripHTML']=='true'){$message_body = strip_tags($message_body);$message_type='text';}
     
    try{
    	include "libmail.php";
    	$m= new Mail("utf-8");
    	$m->From($user_email);
    	$m->To($owner_email);
    	$m->Subject($subject);
    	$m->Body($message_body,$message_type);
    	//$m->log_on(true);
     
    	if(isset($_FILES['attachment'])){
    		if($_FILES['attachment']['size']>$max_file_size){
    			$error_text=$error_text_filesize . ' ' . $max_file_size . 'bytes';
    			die($error_text);			
    		}else{			
    			if(preg_match($file_types,$_FILES['attachment']['name'])){
    				$m->Attach($_FILES['attachment']['tmp_name'],$_FILES['attachment']['name'],'','attachment');
    			}else{
    				$error_text=$error_text_filetype;
    				die($error_text);				
    			}
    		}		
    	}
    	if(!$use_smtp){
    		$m->smtp_on( $host, $username, $password, $port);
    	}
     
    	if($m->Send()){
    		die('success');
    	}	
     
    }catch(Exception $mail){
    	die($mail);
    }	
    ?>

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

Discussions similaires

  1. envoi de formulaire par mail en php
    Par ctopo dans le forum Langage
    Réponses: 4
    Dernier message: 10/11/2014, 01h36
  2. Envoi d'un formulaire par mail
    Par Néoservices dans le forum Langage
    Réponses: 0
    Dernier message: 30/09/2013, 15h46
  3. Envoi d'un formulaire par mail
    Par jer75 dans le forum Langage
    Réponses: 1
    Dernier message: 02/05/2008, 21h46
  4. Envoi d'un formulaire par mail
    Par Leimi dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 02/08/2007, 15h59
  5. [Mail] Problème envoi formulaire par mail
    Par Nicos77 dans le forum Langage
    Réponses: 5
    Dernier message: 10/11/2005, 17h11

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