/users/patterns/www/contactform/class/class.contactform.php


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
<?php

class contactForm{
    
        
    function 
contactForm($cfg)
    {
        
        
/***********************************************************************************************************************************
         * CONFIGURATION 
         *
         * $this->cfg['emailaddress']: the email address on which you want to receive the messages from users through your website
         * $this->cfg['confirmation_email_subject']: the subject of the email containing the message sent by users through your website
         * 
         */
        
$this->cfg['captacha_length'] = 6;
        
        
$this->cfg['emailaddress'] = $cfg['email'];
        
        
$this->cfg['confirmation_email_subject'] = 'New message sent from your website';
        
        
$this->cfg['form_validationmessage'] = $cfg['form_validationmessage'];
        
        
$this->cfg['form_error_captcha'] = $cfg['form_error_captcha'];
        
$this->cfg['form_error_emptyfield'] = $cfg['form_error_emptyfield'];
        
$this->cfg['form_error_invalidemailaddress'] = $cfg['form_error_invalidemailaddress'];
        
$this->cfg['form_validationmessage'] = $cfg['form_validationmessage'];
        
$this->cfg['form_emailnotificationinputid'] = $cfg['form_emailnotificationinputid'];
        
$this->cfg['form_emailnotificationtitle'] = $cfg['form_emailnotificationtitle'];
        
$this->cfg['form_emailnotificationmessage'] = $cfg['form_emailnotificationmessage'];
        
        
        
$this->mailheaders_brut  "From: ".$this->cfg['emailaddress']."<".$this->cfg['emailaddress'].">\r\n";
        
$this->mailheaders_brut .= "Reply-To: ".$this->cfg['emailaddress']."<".$this->cfg['emailaddress'].">\r\n";
        
$this->mailheaders_brut .= "MIME-Version: 1.0\r\n";
        
$this->mailheaders_brut .= "Content-type: text/plain; charset=utf-8\r\n";
        
$this->mailheaders_brut .= "X-Mailer: PHP/".phpversion()."\r\n";
        
        
$this->demo 0;
        
$this->envato_link 'http://codecanyon.net/item/contact-form-generator/1719810';
    }
    
    
    function 
sendMail()
    {
        
$mail_body .= 'You received a new message: '.date("F j, Y, g:i A")
                    .
"\r\n"."--------------------------------------------------------";

        if(
$this->merge_post)
        {
            foreach(
$this->merge_post as $value)
            {
                
$mail_body .= "\r\n\r\n".$this->quote_smart($value['elementlabel']).': '.$this->quote_smart($value['elementvalue']);
            }
        }
        
        
$mail_body .= "\r\n\r\n"."--------------------------------------------------------";
        
$mail_body .= "\r\n".'IP address: '.$_SERVER['REMOTE_ADDR'];
        
$mail_body .= "\r\n".'Host: '.gethostbyaddr($_SERVER['REMOTE_ADDR']);
        
        if(
$this->demo != 1)
        {
            
mail($this->cfg['emailaddress'], $this->cfg['confirmation_email_subject'], $mail_body$this->mailheaders_brut);
        }
    }
    
    
    function 
sendMailReceipt($value)
    {
        if(
$this->demo != 1)
        {
            
mail($value['email_address'], $value['form_emailnotificationtitle'], $value['form_emailnotificationmessage'], $this->mailheaders_brut);
        }
    }
    
    function 
mergePost($value)
    {
        
$this->merge_post[$this->merge_post_index]['elementid'] = $value['elementid'];
        
$this->merge_post[$this->merge_post_index]['elementvalue'] = trim($value['elementvalue']);
        
$this->merge_post[$this->merge_post_index]['elementlabel'] = trim($value['label']);
        
$this->merge_post_index++;
    }
    

    function 
isEmail($email)
    {
        
$atom   '[-a-z0-9\\_]';   // authorized caracters before @
        
$domain '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'// authorized caracters after @
                                       
        
$regex '/^' $atom '+' .   
        
'(\.' $atom '+)*' .         
                                        
        
'@' .                           
        
'(' $domain '{1,63}\.)+' .  
                                        
        
$domain '{2,63}$/i';          
        
        
// test de l'adresse e-mail
        
return preg_match($regextrim($email)) ? 0;
        
    }
    
    
    function 
quote_smart($value)
    {
        if(
get_magic_quotes_gpc())
        {
            
$value stripslashes($value);
        }
        
        return 
$value;
    }

    
    
}
?>