PHP mail() met inline afbeeldingen

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

C -

C -

29/03/2014 15:39:49
Quote Anchor link
Hallo allen,

Ik ben bezig met een versimpelde vorm van een webshop idee, en hiervoor wil ik mailtjes gaan sturen op het moment dat iemand iets besteld heeft en voor de nieuwsbrieven. echter wil ik boven aan deze mails de header van de website hergebruiken dus ik krijg een html mail. het script dat ik momenteel heb werkt prima op een punt na, bij hotmail krijg ik geen van de afbeeldingen te zien, bij gmail wel.

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
171
172
173
<?php
include 'connect.php';
$id=$_POST['id'];
$query = 'SELECT Titel, Prijs, Status as s, Picture FROM Artikel WHERE id='.$id;
$res = mysqli_query($con, $query) or die('Er ging iets mis'. mysqli_error($con));
$row = mysqli_fetch_array($res);
if($row['s']==1){
    $name = $_POST['naam'];
    $lastname = $_POST['anaam'];
    $email = $_POST['mail1'];
    $straat = $_POST['straat'];
    $postcode = $_POST['post'];
    $huisnr = $_POST['huisnr'];
    $test = $_POST['testhuman'];
    $img = 'http://joelle.ict-port.com/'. substr($row['Picture'], 6);
    echo $img;
    $message = '
        <!DOCTYPE html>
        <html>
            <head>
            <title>
                Uw bestelling
            </title>
            <style>
                body{
                    background-color:e17dec;
                }
                
                #container{
                    margin: 0 auto;
                    width: 800px;
                }
                
                #gegevens{
                    float: left;
                    margin-left: 80px;
                    width: 400px;    
                }
                
                #foto{
                    float: left;
                    width: 300px;    
                }
            </style>
            </head>
            <body>
                <div id="container">
                    <img src="http://joelle.ict-port.com/img/logo.png" height="200" alt="logo" width="800" /><br />
                    <br />
                    <center>
                        Bedankt voor uw bestelling! controleer a.u.b uw gegevens.<br />
                        Mochten deze onjuist zijn neem zo snel mogelijk contact met ons op onder vermelding van het Bestellings ID<br />
                    </center>
                    <div id="gegevens">
                        <table>
                            <tr>
                                <td>
                                    Bestellings ID:
                                </td>
                                <td>
                                    '
.$id.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Artikel naam:
                                </td>
                                <td>
                                    '
.$row['Titel'].'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Naam:
                                </td>
                                <td>
                                    '
.$name.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Achternaam klant:
                                </td>
                                <td>
                                    '
.$lastname.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Email klant:
                                </td>
                                <td>
                                    '
.$email.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Straat klant:
                                </td>
                                <td>
                                    '
.$straat.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Huisnummer klant:
                                </td>
                                <td>
                                    '
.$huisnr.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Postcode klant:
                                </td>
                                <td>
                                    '
.$postcode.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Prijs:
                                </td>
                                <td>
                                    '
.$row['Prijs'].'
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="foto">
                        <img src="'
.$img.'" alt="Jouw aankoop" height="200" width="200" />
                    </div>
                </div>
            </body>
        </html>
    '
;
          if($test=="human"){
              $to = $email;
              $errormail = '[email protected]';
              $website_naam = 'joelle.ict-port.com';
              $html = true;
              
              if(empty($to) || empty($email) || empty($message)){
                  echo 'one of the variables is not set';
              }

              else{
                  $headers     = 'From: ' . '[email protected]' . ' <' . '[email protected]' . '>' . "\r\n";
                $headers    .= 'Reply-To: ' . '[email protected]' . ' <' . '[email protected]' . '>' . "\r\n";
                $headers    .= 'Return-Path: Mail-Error <' . $errormail . '>' . "\r\n";
                $headers    .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
                $headers    .= 'X-Priority: Normal' . "\r\n";
                $headers     .= "MIME-Version: 1.0\r\n";
                $headers     .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                
                
                  mail($to, $subject, $message, $headers);
                  header('Location: ../index.php');
              }
              }

              else if($row['s']==2){
                  echo 'Dit artikel is gereserveerd.</br>';
              }

              else{
                  echo  'Dit artikel is niet gevonden.<br />';    
              }
      }

      else if($test=="robot"){
          echo "You look like a spambot";
      }

      else{
          echo "can't find antispam test";
      }

?>
 
PHP hulp

PHP hulp

29/03/2024 09:31:17
 
Donny Wie weet

Donny Wie weet

29/03/2014 16:02:52
Quote Anchor link
Het advies wat elke programmeur mij heeft gegeven: gebruik swiftmailer of PHPmailer. Ikzelf gebruik PHPmailer waardoor je in maximaal 10 regels je mail kan samenstellen :)

Helaas heb ik geen idee waarom je image het niet doet in Hotmail
 
C -

C -

29/03/2014 16:51:29
Quote Anchor link
@donny ik heb weleens van phpmailer gehoord nog nooit mee gewerkt, echter probeer ik altijd afhankelijkheid van andere packages te voorkomen....
 
Donny Wie weet

Donny Wie weet

29/03/2014 17:30:59
Quote Anchor link
Ik denk dat ik namens iedereen spreek als ik zeg: "waarom zou je het wiel opnieuw uitvinden?"...

Waarom wil je 50 regels code schrijven, als je er al met 10 bent?
 
Ward van der Put
Moderator

Ward van der Put

29/03/2014 17:32:33
Quote Anchor link
Je gebruikt headers die kenmerkend zijn voor spam: From noreply@ en Reply to noreply@. Dat laatste is ook niet bepaald logisch: reply to noreply...
 
C -

C -

29/03/2014 19:54:17
Quote Anchor link
@ward, dat is misschien wel handig om aan te passen ja...
 
Obelix Idefix

Obelix Idefix

30/03/2014 12:07:09
Quote Anchor link
Niet elke webmaildienst laat nog afbeeldingen zien. Dit volgens mij uit veiligheidsoverwegingen.
Ook bij Gmail heb ik met enige regelmaat dat ik niet de afbeelingen zien (kan ze wel opvragen).
Ook in Outlook en Thunderbird worden afbeeldingen niet (altijd) automatisch getoond.
 
- Ariën  -
Beheerder

- Ariën -

30/03/2014 16:32:09
Quote Anchor link
Gmail toont de afbeeldingen sinds kort via een eigen proxy.
 
C -

C -

30/03/2014 18:10:32
Quote Anchor link
ik heb met gmail totaal geen problemen.... echter alleen met hotmail...
ik heb de phpmailer class geimplementeerd en heb nu dit:
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
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>PHPMailer - mail() test</title>
</head>
<body>
<?php
require 'mail/PHPMailerAutoload.php';

    $name = $_POST['naam'];
    $lastname = $_POST['anaam'];
    $email = $_POST['mail1'];
    $straat = $_POST['straat'];
    $postcode = $_POST['post'];
    $huisnr = $_POST['huisnr'];
    $test = $_POST['testhuman'];
    $img = 'http://joelle.ict-port.com/'. substr($row['Picture'], 6);
    $message = '
        <!DOCTYPE html>
        <html>
            <head>
            <title>
                Uw bestelling
            </title>
            <style>
                body{
                    background-color:e17dec;
                }
                
                #container{
                    margin: 0 auto;
                    width: 800px;
                }
                
                #gegevens{
                    float: left;
                    margin-left: 80px;
                    width: 400px;    
                }
                
                #foto{
                    float: left;
                    width: 300px;    
                }
            </style>
            </head>
            <body>
                <div id="container">
                    <img src="http://joelle.ict-port.com/img/logo.png" height="200" alt="logo" width="800" /><br />
                    <br />
                    <center>
                        Bedankt voor uw bestelling! controleer a.u.b uw gegevens.<br />
                        Mochten deze onjuist zijn neem zo snel mogelijk contact met ons op onder vermelding van het Bestellings ID<br />
                    </center>
                    <div id="gegevens">
                        <table>
                            <tr>
                                <td>
                                    Bestellings ID:
                                </td>
                                <td>
                                    '
.$id.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Artikel naam:
                                </td>
                                <td>
                                    '
.$row['Titel'].'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Naam:
                                </td>
                                <td>
                                    '
.$name.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Achternaam klant:
                                </td>
                                <td>
                                    '
.$lastname.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Email klant:
                                </td>
                                <td>
                                    '
.$email.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Straat klant:
                                </td>
                                <td>
                                    '
.$straat.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Huisnummer klant:
                                </td>
                                <td>
                                    '
.$huisnr.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Postcode klant:
                                </td>
                                <td>
                                    '
.$postcode.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Prijs:
                                </td>
                                <td>
                                    '
.$row['Prijs'].'
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="foto">
                        <img src="'
.$img.'" alt="Jouw aankoop" height="200" width="200" />
                    </div>
                </div>
            </body>
        </html>
    '
;

//Create a new PHPMailer instance
$mail = new PHPMailer();
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'Bestel joelle.ict-port.com');
//Set an alternative reply-to address
//$mail->addReplyTo('[email protected]', 'First Last');
//Set who the message is to be sent to

$mail->addAddress('[email protected]', 'cyvan oort');
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body

$mail->msgHTML($message);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
    echo "Message sent!";
}

?>

</body>
</html>


en heb exact hetzelfde probleem, gmail ziet hem wel en hotmail niet :S
 
Ivo P

Ivo P

30/03/2014 21:28:44
Quote Anchor link
Je zou de afbeelding ook mee kunnen sturen, of inline in de html verpakken.
Mits je mail dan niet vele MB groot wordt
 
Michael -

Michael -

31/03/2014 08:18:01
Quote Anchor link
Mogelijk sta je bij hotmail in de trust lijst, maar ik kan me goed voorstellen dat ze allemaal geen links van externe bronnen automatisch tonen.
Het makkelijkste vind ik om de afbeeldingen mee te sturen.
Ook zie ik dat je HTML niet aan staat, maar misschien dat dit default al is.

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
171
172
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>PHPMailer - mail() test</title>
</head>
<body>
<?php
require 'mail/PHPMailerAutoload.php';

    $name = $_POST['naam'];
    $lastname = $_POST['anaam'];
    $email = $_POST['mail1'];
    $straat = $_POST['straat'];
    $postcode = $_POST['post'];
    $huisnr = $_POST['huisnr'];
    $test = $_POST['testhuman'];
    $img = 'http://joelle.ict-port.com/'. substr($row['Picture'], 6);
    $message = '
        <!DOCTYPE html>
        <html>
            <head>
            <title>
                Uw bestelling
            </title>
            <style>
                body{
                    background-color:e17dec;
                }
                
                #container{
                    margin: 0 auto;
                    width: 800px;
                }
                
                #gegevens{
                    float: left;
                    margin-left: 80px;
                    width: 400px;    
                }
                
                #foto{
                    float: left;
                    width: 300px;    
                }
            </style>
            </head>
            <body>
                <div id="container">
                    <!-- Inline image weergeven -->
                <img src="cid:logoimg" height="200" alt="logo" width="800" /><br />
                    <br />
                    <center>
                        Bedankt voor uw bestelling! controleer a.u.b uw gegevens.<br />
                        Mochten deze onjuist zijn neem zo snel mogelijk contact met ons op onder vermelding van het Bestellings ID<br />
                    </center>
                    <div id="gegevens">
                        <table>
                            <tr>
                                <td>
                                    Bestellings ID:
                                </td>
                                <td>
                                    '
.$id.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Artikel naam:
                                </td>
                                <td>
                                    '
.$row['Titel'].'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Naam:
                                </td>
                                <td>
                                    '
.$name.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Achternaam klant:
                                </td>
                                <td>
                                    '
.$lastname.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Email klant:
                                </td>
                                <td>
                                    '
.$email.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Straat klant:
                                </td>
                                <td>
                                    '
.$straat.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Huisnummer klant:
                                </td>
                                <td>
                                    '
.$huisnr.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Postcode klant:
                                </td>
                                <td>
                                    '
.$postcode.'
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Prijs:
                                </td>
                                <td>
                                    '
.$row['Prijs'].'
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="foto">
                        <!-- Inline image weergeven -->
                        <img src="cid:aankoop" alt="Jouw aankoop" height="200" width="200" />
                    </div>
                </div>
            </body>
        </html>
    '
;

//Create a new PHPMailer instance
$mail = new PHPMailer();
//Set who the message is to be sent from
$mail->setFrom('*', 'Bestel *');
//Set an alternative reply-to address
//$mail->addReplyTo('[email protected]', 'First Last');
//Set who the message is to be sent to

$mail->addAddress('*', '*');
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body

$mail->msgHTML($message);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');

$mail->IsHTML(true); // HTML
$mail->AddEmbeddedImage(__DIR__ . '/img/logo.png' , 'logoimg'); // Inline image meesturen
$mail->AddEmbeddedImage(__DIR__ . '/' . $img, 'aankoop');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
    echo "Message sent!";
}

?>

</body>
</html>
Gewijzigd op 31/03/2014 08:19:13 door Michael -
 
C -

C -

01/04/2014 14:27:25
Quote Anchor link
ik heb het maar via de oude methode gedaan (de mail functie van php zelf) en dan een koppeling naar een online versie die het wel doet

alsnog iedereen bedankt
 



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.