Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

PHP email $to uit database

Pagina: 1
Acties:

  • World Citizen
  • Registratie: Oktober 2002
  • Laatst online: 18:06
Hoi,

Ik zit met een probleem. Ik ben net aan het beginnen met PHP en loop tegen iets aan wat ik niet begrijp.


Ik heb een contactformulier wat afhankelijk van de pagina waar je op zit een mail moet sturen naar een bepaald email adres.

In de eerste instantie heb ik het volgende gemaakt.
code:
1
<a href="mailto:{shop_email}?subject=Informatie aanvraag via Website - {title}&CC=info@website.nl" class="informatie-direct" >Informatie aanvragen</a>-->



En dat werkt. In het PHP document staat het volgende wat dat mogenlijk maakt.

code:
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
private function _setShopData() {
        $shopcounter=0;
        
        

        foreach($this->_shops as $shop) {
            $this->setVariable('shop_title',$shop['name']);
            $this->setVariable('shop_address',$shop['address']);
            $this->setVariable('shop_zip',$shop['postcode']);
            $this->setVariable('shop_city',$shop['city']);



                $this->setVariable('shop_email',$shop['email']);



            $this->setVariable('shops_url', $shop['urlname'] . '/producten/');
            $this->setVariable('shop_phonenumber',$shop['telephone']);
            $description = strip_tags($shop['description'],'<br><br />');
            $this->setVariable('shop_description',$description);
            if ($shop['logoimg'] != '') {
                $this->setVariable('shop_logo',$shop['logoimg']);
            }
            if (count($this->_shops) -1 != $shopcounter) {
                $this->touchBlock('LINESMALL');
            }
            
            $shopcounter++;
            $this->Parse('SHOP');
        }
        
        if (isset($this->_shops[0]['impression_code']) && $this->_shops[0]['impression_code'] != '') {
            $this->_shops[0]['impression_code'] = str_replace('{ORDER}',niceUrl($this->_product['fulltitle']),$this->_shops[0]['impression_code']);
            $this->setVariable('impression_code',$this->_shops[0]['impression_code']);
        }
        
    }



Maar ik zie liever een mooi contact formulier ipv een mailto:
Dus, Ik heb een contact formulier gevonden en deze geplaatst. Dit werkt, alleen moet ik hard een email adres invullen waar hij het naartoe stuurt.
Dat ziet er zo uit:

code:
1
2
3
4
5
        $to      = 'ontvanger@gmail.com';
        $subject = 'Informatie aanvraag';
        $message = 'Naam:' . $db->string($_POST['naam']) . "\n" . 'Email:' . $db->string($_POST['email']) . "\n" . 'Telefoon:' . $db->string($_POST['telefoon']) . "\n" . 'Bericht:' . $db->string($description);  
        $headers = 'From: info@website.nl' . "\r\n" .
    'Reply-To: info@website.nl' . "\r\n" .



Hoe kan ik er nu voor zorgen dat deze $to ook het email adres uit de database pakt. Ik wil dus eigenlijk een zelfde constructie als in het eerste voorbeeld wat goed werkte.
Mijn kennis is hier net iets te klein voor. Het formulier werkt perfect met een hard ingevuld adres... Alle functie werken naar behoren. Ik wil dus enkel nog het $to adres afhankelijk maken van de pagina waar je op zit.

Hoe moet ik dit bekijken, en wat moet ik begrijpen. De uiteindelijk code komt wel, maar ik begrijp dit simpelweg niet waardoor ik ook niet weet hoe ik moet beginnen.


Excuses voor mijn beginners niveau

Alvast super bedankt.

FreeReef.nl


  • Ealanrian
  • Registratie: Februari 2009
  • Laatst online: 18:20
In je eerste code heb je een variable waarin je shop email staat. Je hebt een variable $to waar het email adres in moet. Probeer eens 1+1 te combineren

  • Groentjuh
  • Registratie: September 2011
  • Laatst online: 08:36
In het tweede blok code(met _setShopData()) wat je hebt gepost staat: $shop['email']. Dat is de waarde waar de email inderdaad inzit. Ik geloof dat je daar in een template engine zit, dus het is elders opgehaald..

Die $shop waarde komt uit "$this->_shops". Ook die wordt ergens een keer opgehaald/gezet. Ga eens kijken waar die vandaan komt en daarna hoe je die email-waarde naar de email code kan krijgen.

Met deze informatie kan ik niets concreter zeggen.

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 20-11 11:59

NMe

Quia Ego Sic Dico.

Ealanrian schreef op woensdag 18 september 2013 @ 12:17:
In je eerste code heb je een variable waarin je shop email staat. Je hebt een variable $to waar het email adres in moet. Probeer eens 1+1 te combineren
^^ dat inderdaad. In je huidige code heb je alles wat je nodig hebt al, je vrijwel hoeft alleen variabelenamen te vervangen. Wat begrijp je precies niet? :?

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • World Citizen
  • Registratie: Oktober 2002
  • Laatst online: 18:06
Dat dacht ik inderdaad ook.

Alleen stond de mailto varriant in een ander php bestand dan waar ik nu in aan het werk ben. Ik open nu namelijk een overlay en in die overlay zit mijn formulier. Die overlay heeft een eigen php bestand, en daar is de variabel niet in opgenomen, dus ik kan hem niet aanroepen. Nu heb ik een hoop proberen te kopiëren, maar dit resulteert vooral in errors.


Uit jullie antwoorden maak ik wel op dat ik denk ik in de juiste richting denk.


Ik heb nu het volgende php bestand wat uiteindelijk moet gaan werken. Hier staat dus helemaal onderaan de $to referentie.

Alleen valt mij meteen op dat hier nergens de variabel voor shop_mail word aangemaakt. (dat is ook wat jullie zeggen toch?)


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

require_once(SIT_CLASS_DIR . '/class.website.php');

class app_public_pageajax {

    function __construct() {
        global $bootParam,$routes;
        

        if (isset($_GET['ajaxurl'])) {
            // Simulate webboot
            $urlArr = urlToArray(str_replace('http://' . $_SERVER['SERVER_NAME'],'',$_GET['ajaxurl']));
    
                $chars = preg_split('/\?|\&/',strstr($_GET['ajaxurl'], '?'));
                foreach($chars as $char) {
                    $c = explode("=",$char);
                    $_GET[$c[0]] = $c[1];
                }
                
                // BOOT ACTION 1
                if (isset($urlArr[0])) {
                    $bootParam['main']  = $urlArr[0];
                } else {
                    $bootParam['main']  = null;
                }
                
                // BOOT ACTION 2
                if (isset($urlArr[1])) {
                    $bootParam['2'] = $urlArr[1];
                } else {
                    $bootParam['2'] = null;
                }
                
                if (isset($urlArr[2])) {
                    $bootParam['3'] = $urlArr[2];
                } else {
                    $bootParam['3'] = null;
                }
                
                if (isset($urlArr[3])) {
                    $bootParam['4'] = $urlArr[3];
                } else {
                    $bootParam['4'] = null;
                }
                
                $bootParam['ajax'] = true;
            }
            
        $this->actions();
    }
    
    function actions() {
        if (isset($_GET['subAction'])) {
            switch($_GET['subAction']) {
                
                case "aanvraag":
                    $this->_aanvraag();
                break;

                case "newsletter":
                    $this->_newsletter();
                break;

                
                case "default":
                    exit;
                break;
            }
        }
    }
    

    private function _newsletter() {
        $db = new Db();
        $db->write('INSERT INTO newsletter SET name = "' . $db->string($_POST['name']) . '",
                                                                                                    email = "' . $db->string($_POST['email']) . '",
                                                                                                    time = "' . time() . '"');
        


    

        
        exit;
    }   
    
    private function _aanvraag() {
        $db = new Db();
        $url = str_replace('http://website.xt','',$_SERVER['HTTP_REFERER']);
        $url = str_replace('http://www.website.nl','',$url);
        $url = str_replace('http://website','',$url);
        $description = "Product: " . $url . "\n\n" . $_POST['beschrijving'];
        $db->write('INSERT INTO informatieaanvraag SET naam = "' . $db->string($_POST['naam']) . '",






                                                                                                    email = "' . $db->string($_POST['email']) . '",
                                                                                                    telefoon = "' . $db->string($_POST['telefoon']) . '",
                                                                                                    beschrijving = "' . $db->string($description) . '",
                                                                                                    datum = "' . $db->string(time()) . '"');
        


        $to      = 'website@gmail.com';
        $subject = 'Informatie aanvraag';
        $message = 'Naam:' . $db->string($_POST['naam']) . "\n" . 'Email:' . $db->string($_POST['email']) . "\n" . 'Telefoon:' . $db->string($_POST['telefoon']) . "\n" . 'Bericht:' . $db->string($description);  
        $headers = 'From: info@website.nl' . "\r\n" .
    'Reply-To: info@website.nl' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

        mail($to, $subject, $message, $headers);        
        
        exit;
    }
    
    public function show() {
        
    }
    
    
}




// =========================================================================================

?>



Ik zal dus ergens in dit document het volgende stuk code kwijt moeten wil ik op dezelfde manier een request aan de database kunnen doen:

code:
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
    private function _setShopData() {
        $shopcounter=0;
        
        

        foreach($this->_shops as $shop) {
            $this->setVariable('shop_title',$shop['name']);
            $this->setVariable('shop_address',$shop['address']);
            $this->setVariable('shop_zip',$shop['postcode']);
            $this->setVariable('shop_city',$shop['city']);
                $this->setVariable('shop_email',$shop['email']);
            $this->setVariable('shops_url', $shop['urlname'] . '/producten/');
            $this->setVariable('shop_phonenumber',$shop['telephone']);
            $description = strip_tags($shop['description'],'<br><br />');
            $this->setVariable('shop_description',$description);
            if ($shop['logoimg'] != '') {
                $this->setVariable('shop_logo',$shop['logoimg']);
            }
            if (count($this->_shops) -1 != $shopcounter) {
                $this->touchBlock('LINESMALL');
            }
            
            $shopcounter++;
            $this->Parse('SHOP');
        }
        
        if (isset($this->_shops[0]['impression_code']) && $this->_shops[0]['impression_code'] != '') {
            $this->_shops[0]['impression_code'] = str_replace('{ORDER}',niceUrl($this->_product['fulltitle']),$this->_shops[0]['impression_code']);
            $this->setVariable('impression_code',$this->_shops[0]['impression_code']);
        }
        
    }



En daar loop ik vast omdat ik niet begrijp wat de functies exact doen.

Welk stuk van de code is belangrijk en moet wel gekopieerd worden en welk stuk niet. Ook de locatie waar ik dit weg moet zetten in het voorgaande php document is mij een raadsel. Ik snap dus wat ik te kort kom en in welk document het moet komen te staan. Maar hoe precies weet ik dus niet.

FreeReef.nl


  • Ealanrian
  • Registratie: Februari 2009
  • Laatst online: 18:20
In je tweede stuk code vul je $shop van uit een andere variable. Ik neem even aan dat deze variable wel beschikbaar is in je "overlay". Met die variable zou je dus moeten kunnen werken.
$this->_shops

En wanneer je code post, post alleen relevante code A.U.B. dit zijn wel vrij grote brokken

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 20-11 11:59

NMe

Quia Ego Sic Dico.

Misschien moet je gewoon bij het begin beginnen met leren en niet twee willekeurige stukken script samen proberen te gooien vóór je de basis beheerst? Je vraag is érg simpel maar tegelijkertijd kunnen we er niet direct een sluitend antwoord op geven omdat we niet de hele situatie (kunnen) kennen.

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • CH4OS
  • Registratie: April 2002
  • Niet online

CH4OS

It's a kind of magic

Bedenk je wel, als je de e-mailadressen in de HTML output zet, dat dat voer is voor spambots. Ik zou dus voorkomen dat er door indexatie van spambots extra mailverkeer op de mailboxen binnenkomt. Probeer dus zoveel mogelijk te voorkomen dat er e-mailadressen in je output verdwijnen en gebruik (re)Captcha om te voorkomen dat er naar hartelust een formulier ingevuld (kan) worden.
Pagina: 1