Echo result van php script doorsturen via mail

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Greg gil

greg gil

15/11/2015 14:02:58
Quote Anchor link
Beste mensen,

Ik heb een script.. Alles werkt perfect en het doorsturen via dompdf lukt heel goed.
Alleen de uitvoering van mijn berekening kan niet mee doorgestuurd worden. (echo $answer)
Het rare is echter dat wanneer ik bvb $total gebruik, het wel mee doorgestuurd wordt maar dat het resultaat echter 0 is dus ik veronderstel dat het script niet uitgevoerd wordt.
Alles werkt perfect alleen de uitkomst van mijn berekening kan ik niet mee doorsturen.


Hieronder mijn script..
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
$sympathisant
=151.25;
$brons=25;
$perssymp=151.25;
$persbrons=25;

$total=0;

if(isset($_POST['sympathisant']) && $_POST['sympathisant']=='1')
{

$answer = $sympathisant ;
}


if(isset($_POST['brons']) && $_POST['brons']=='1')
{

$answer =$brons;
}

if(isset($_POST['perssymp']))
{

    $num=(int)$_POST['perssymp']; // make sure only integers are accepted
    if($num>0) // ignore negative values
    {
        $answer=$total+($perssymp*$num);
    }
}

if(isset($_POST['persbrons']))
{

    $num=(int)$_POST['persbrons']; // make sure only integers are accepted
    if($num>0) // ignore negative values
    {
        $answer=$total+($persbrons*$num);
    }
}


echo "Total price is \$$answer\n";



if (!empty($_POST)) {

    // Used for later to determine result
    $success = $error = false;

    // Object syntax looks better and is easier to use than arrays to me
    $post = new stdClass;
    
    // Usually there would be much more validation and filtering, but this
    // will work for now.

    foreach ($_POST as $key => $val)
        $post->$key = trim(strip_tags($_POST[$key]));
        
    // Check for blank fields
    if (empty($post->name) OR empty($post->email))
        $error = true;
        
    else {
        
        // Get this directory, to include other files from
        $dir = dirname(__FILE__);
        
        // Get the contents of the pdf into a variable for later
        ob_start();
        require_once($dir.'/pdf.php');
        $pdf_html = ob_get_contents();
        ob_end_clean();
        
        // Load the dompdf files
        require_once($dir.'/dompdf/dompdf_config.inc.php');
        
        $dompdf = new DOMPDF(); // Create new instance of dompdf
        $dompdf->load_html($pdf_html); // Load the html
        $dompdf->render(); // Parse the html, convert to PDF
        $pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
        
        // Get the contents of the HTML email into a variable for later

        ob_start();
        require_once($dir.'/html.php');
        $html_message = ob_get_contents();
        ob_end_clean();
        
        // Load the SwiftMailer files
        require_once($dir.'/swift/swift_required.php');

        $mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer

        $message = Swift_Message::newInstance()
                       ->
setSubject('How To Create and Send An HTML Email w/ a PDF Attachment') // Message subject
                       ->setTo(array($post->email => $post->name)) // Array of people to send to
                       ->setFrom(array('[email protected]' => 'Eindejaarsconcert')) // From:
                        ->setCc(array('[email protected]'))
                       ->
setBody($html_message, 'text/html') // Attach that HTML message from earlier
                       ->attach(Swift_Attachment::newInstance($pdf_content, 'nettuts.pdf', 'application/pdf')); // Attach the generated PDF from earlier
                      
        // Send the email, and show user message

        if ($mailer->send($message))
            $success = true;
        else
            $error = true;
        
    }

}


?>



<html>
    <head>
        </head>
        <body>
                <?php if ($success) { ?>
            <div class="message success">
                <h4>Congratulations! It worked! </h4>
            </div>
        <?php } elseif ($error) { ?>
            <div class="message error">
                <h4>Sorry, an error occurred. Try again!</h4>
            </div>
        <?php } ?>
<form id="pricecalculation" method="post" action="">
<table>
<tr>
<td><label for="name">Your Name:</label></td>
<td><input type="text" name="name" id="name" class="input" /></td>
<td><label for="email">Your Email:</label>
<td><input type="text" name="email" id="email" class="input" /></td>
<tr>
<td>Vip arrangement </td>
<td>
<select name="sympathisant"  id="sympathisant">  
        <option value="viparrangement">Ja</option>  
        <option value="">Nee</option>  
    </select> </td>
</tr>

<tr>
<td>Hoeveel personen? </td>
<td><input id="hoeveelpersonen1"name="perssymp"  id="perssymp" size="3"></td>
</tr>
</br>
<tr>

<tr>
<td>Ticket </td>
<td>
<select name="brons" id="brons">  
        <option value="Ticket">Ja</option>  
        <option value="">Nee</option>  
    </select> </td>
</tr>
</tr>
<tr>
<tr>
<td>Hoeveel personen? </td>
<td><input name="persbrons" id="hoeveelpersonen2" type="text" id="persbrons" size="3"></td>
</tr>
<tr>
<input name="totaal" type="text" id="totaal" name="totaal" value=<?php echo "$answer"; ?>>
</tr>
</table>

<input name="submit" type="submit" value="Calculate price"/>
</form>

</body>
</html>
[modedit="- Arin -"]Gelieve in het vervolg bij code de [[b][/b]code][[b][/b]/code]-tags gebruiken.
[url=http://www.phphulp.nl/veel-gestelde-vragen/#bbcode]Hier[/url] kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt![/modedit]
[modedit="- Arin -"]Dit topic is verplaatst naar de juiste categorie.[/modedit]
Gewijzigd op 07/12/2015 13:04:00 door - Ariën -
 
PHP hulp

PHP hulp

27/04/2024 20:39:50
 
Thomas van den Heuvel

Thomas van den Heuvel

22/11/2015 16:29:32
Quote Anchor link
Verkeerde forum.
 
- SanThe -

- SanThe -

22/11/2015 16:41:31
Quote Anchor link
Zet error reporting aan.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.