Mail attachement wilt niet werken
Goeiemiddag, ik ben bezig met een mail script om via een formulier, netjes in HTML een mail te sturen met attachement. Nu wilt ie wel de mail met HTML sturen alleen de attachement krijg ik niet werkend.
Sorry voor de on overoverzichtelijke code, ik weet dat het niet netjes is en bestaat uit van alles en nog wat. Maar hij doet het tenminste (gedeeltelijk) :)
Wat ik in mijn mail krijg:
De code:
Sorry voor de on overoverzichtelijke code, ik weet dat het niet netjes is en bestaat uit van alles en nog wat. Maar hij doet het tenminste (gedeeltelijk) :)
Wat ik in mijn mail krijg:
Quote:
This is a multi-part message in MIME format. --6657a30d9b77d2e80a65b8aaafafc80f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit --6657a30d9b77d2e80a65b8aaafafc80f Content-Type: application/xml; name="Rabobank.png" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Rabobank.png"
Gebruikersnaam: rubjo99
Volledige naam: ruben kok
Klantnummer: 1234567890
Productnaam: Hurdur 827UI
Artikelnummer 1234567890
Badgenummer 10.09.29.09
Aantal 2
Aankoopdatum rubjo99
Klantenreferentie rubjo99
Klachtomschrijving:
HURDHURUDHUHSUDHSUDHUSADH
--6657a30d9b77d2e80a65b8aaafafc80f--
Gebruikersnaam: rubjo99
Volledige naam: ruben kok
Klantnummer: 1234567890
Productnaam: Hurdur 827UI
Artikelnummer 1234567890
Badgenummer 10.09.29.09
Aantal 2
Aankoopdatum rubjo99
Klantenreferentie rubjo99
Klachtomschrijving:
HURDHURUDHUHSUDHSUDHUSADH
--6657a30d9b77d2e80a65b8aaafafc80f--
De code:
Code (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
<?PHP
$klnummer = $_POST[klantNummer];
$arnummer = $_POST[artikelNummer];
// Configuration - Your Options
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
$filename = $_FILES['fileAttach']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['fileAttach']['tmp_name'],$upload_path . $filename)) {
echo "Bestand is geupload";
}
if (!isset($_REQUEST["userName"], $_REQUEST["fullName"], $_REQUEST["klantNummer"], $_REQUEST["productNaam"], $_REQUEST["artikelNummer"], $_REQUEST["badgeNummer"], $_REQUEST["klachtDesc"], $_REQUEST["klantRef"]))
{
echo "Je hebt 1 van de velden niet ingevuld";
}
elseif (!eregi( "^[0-9]+$", $klnummer )) {
echo "Het artikelnummer en/of klantenummer kan alleen cijfers bevatten!";
}
elseif (!eregi( "^[0-9]+$", $arnummer )) {
echo "Het artikelnummer en/of klantenummer kan alleen cijfers bevatten!";
}
else
{
$mailInfo=array();
foreach($_POST as $k=>$v){
if($k!='day' && $k!='month' && $k!='year'){
$mailInfo[$k]=htmlspecialchars($_POST[$k]);
}
}
$aankoopdatum = "".$_REQUEST["day"]."-".$_REQUEST["month"]."-".$_REQUEST["year"]."";
$to = "[email protected]";
$from = "From:". $mailInfo['fullName'] ."";
$eigen_emailadres = '[email protected]';
$error_emailadres = '[email protected]';
$naam_verzender = 'Afzender';
$email_verzender = '[email protected]';
$bcc_emailadres = '';
$html = true;
/* Attachment File */
// Attachment location
$file_name = $_FILES['fileAttach']['name'];
$path = "./uploads/";
// Generate a boundary
$boundary = md5(uniqid(time()));
// Read the file content
$file = $path.$file_name;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($message));
// Email content
$message = "<html><body>";
$message .= "<table>";
$message .= "<tr><td>Gebruikersnaam:</td><td>".$mailInfo['userName']."</td></tr>";
$message .= "<tr><td>Volledige naam:</td><td>".$mailInfo['fullName']."</td></tr>";
$message .= "<tr><td>Klantnummer:</td><td>".$mailInfo['klantNummer']."</td></tr>";
$message .= "<tr><td>Productnaam:</td><td>".$mailInfo['productNaam']."</td></tr>";
$message .= "
<tr>
<td>Artikelnummer</td>
<td>".$mailInfo['artikelNummer']."</td>
</tr>
<tr>
<td>Badgenummer</td>
<td>".$mailInfo['badgeNummer']."</td>
</tr>
<tr>
<td>Aantal</td>
<td>".$mailInfo['aanTal']."</td>
</tr>
<tr>
<td>Aankoopdatum</td>
<td>".$mailInfo['userName']."</td>
</tr>
<tr>
<td>Klantenreferentie</td>
<td>".$mailInfo['userName']."</td>
</tr>";
$message .= "<tr><td>Klachtomschrijving:</td><td><pre style='font-size:12px;'>".$mailInfo['klachtDesc']."</pre></td></tr>";
$message .="</table>";
$message .="</body></html>";
//Headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $fullname . ' <' . $email_verzender . '>' . PHP_EOL;
$headers .= 'Reply-To: ' . $naam_verzender . ' <' . $eigen_emailadres . '>' . PHP_EOL;
// Multipart wraps the Email Content and Attachment
$headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n". PHP_EOL;
$headers .= "This is a multi-part message in MIME format.\r\n". PHP_EOL;
$headers .= "--".$boundary."\r\n". PHP_EOL;
// Content-type can be text/plain or text/html
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n". PHP_EOL;
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n". PHP_EOL;
$headers .= "$content\r\n". PHP_EOL;
$headers .= "--".$boundary."\r\n". PHP_EOL;
// Attachment
// Edit content type for different file extensions
$headers .= "Content-Type: application/xml; name=\"".$file_name."\"\r\n". PHP_EOL;
$headers .= "Content-Transfer-Encoding: base64\r\n". PHP_EOL;
$headers .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n". PHP_EOL;
$headers .= $message."\r\n". PHP_EOL;
$headers .= "--".$boundary."--". PHP_EOL;
mail($to,"Klachtenformulier",$message,$headers);
echo 'Uw klacht zal zo snel mogelijk worden behandeld';
}
?>
$klnummer = $_POST[klantNummer];
$arnummer = $_POST[artikelNummer];
// Configuration - Your Options
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
$filename = $_FILES['fileAttach']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['fileAttach']['tmp_name'],$upload_path . $filename)) {
echo "Bestand is geupload";
}
if (!isset($_REQUEST["userName"], $_REQUEST["fullName"], $_REQUEST["klantNummer"], $_REQUEST["productNaam"], $_REQUEST["artikelNummer"], $_REQUEST["badgeNummer"], $_REQUEST["klachtDesc"], $_REQUEST["klantRef"]))
{
echo "Je hebt 1 van de velden niet ingevuld";
}
elseif (!eregi( "^[0-9]+$", $klnummer )) {
echo "Het artikelnummer en/of klantenummer kan alleen cijfers bevatten!";
}
elseif (!eregi( "^[0-9]+$", $arnummer )) {
echo "Het artikelnummer en/of klantenummer kan alleen cijfers bevatten!";
}
else
{
$mailInfo=array();
foreach($_POST as $k=>$v){
if($k!='day' && $k!='month' && $k!='year'){
$mailInfo[$k]=htmlspecialchars($_POST[$k]);
}
}
$aankoopdatum = "".$_REQUEST["day"]."-".$_REQUEST["month"]."-".$_REQUEST["year"]."";
$to = "[email protected]";
$from = "From:". $mailInfo['fullName'] ."";
$eigen_emailadres = '[email protected]';
$error_emailadres = '[email protected]';
$naam_verzender = 'Afzender';
$email_verzender = '[email protected]';
$bcc_emailadres = '';
$html = true;
/* Attachment File */
// Attachment location
$file_name = $_FILES['fileAttach']['name'];
$path = "./uploads/";
// Generate a boundary
$boundary = md5(uniqid(time()));
// Read the file content
$file = $path.$file_name;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($message));
// Email content
$message = "<html><body>";
$message .= "<table>";
$message .= "<tr><td>Gebruikersnaam:</td><td>".$mailInfo['userName']."</td></tr>";
$message .= "<tr><td>Volledige naam:</td><td>".$mailInfo['fullName']."</td></tr>";
$message .= "<tr><td>Klantnummer:</td><td>".$mailInfo['klantNummer']."</td></tr>";
$message .= "<tr><td>Productnaam:</td><td>".$mailInfo['productNaam']."</td></tr>";
$message .= "
<tr>
<td>Artikelnummer</td>
<td>".$mailInfo['artikelNummer']."</td>
</tr>
<tr>
<td>Badgenummer</td>
<td>".$mailInfo['badgeNummer']."</td>
</tr>
<tr>
<td>Aantal</td>
<td>".$mailInfo['aanTal']."</td>
</tr>
<tr>
<td>Aankoopdatum</td>
<td>".$mailInfo['userName']."</td>
</tr>
<tr>
<td>Klantenreferentie</td>
<td>".$mailInfo['userName']."</td>
</tr>";
$message .= "<tr><td>Klachtomschrijving:</td><td><pre style='font-size:12px;'>".$mailInfo['klachtDesc']."</pre></td></tr>";
$message .="</table>";
$message .="</body></html>";
//Headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $fullname . ' <' . $email_verzender . '>' . PHP_EOL;
$headers .= 'Reply-To: ' . $naam_verzender . ' <' . $eigen_emailadres . '>' . PHP_EOL;
// Multipart wraps the Email Content and Attachment
$headers .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n". PHP_EOL;
$headers .= "This is a multi-part message in MIME format.\r\n". PHP_EOL;
$headers .= "--".$boundary."\r\n". PHP_EOL;
// Content-type can be text/plain or text/html
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n". PHP_EOL;
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n". PHP_EOL;
$headers .= "$content\r\n". PHP_EOL;
$headers .= "--".$boundary."\r\n". PHP_EOL;
// Attachment
// Edit content type for different file extensions
$headers .= "Content-Type: application/xml; name=\"".$file_name."\"\r\n". PHP_EOL;
$headers .= "Content-Transfer-Encoding: base64\r\n". PHP_EOL;
$headers .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n". PHP_EOL;
$headers .= $message."\r\n". PHP_EOL;
$headers .= "--".$boundary."--". PHP_EOL;
mail($to,"Klachtenformulier",$message,$headers);
echo 'Uw klacht zal zo snel mogelijk worden behandeld';
}
?>
Er zijn nog geen reacties op dit bericht.




