PHP email en bijlage

Ik heb zojuist een mailinglist geschreven voor een winkel. Ze kunnen on line emails versturen en personen verwijderen.

Maar nu zouden ze ook graag emails versturen + bijlage.
Ik heb al een upload script gemaakt en via een roll-menu zullen ze dan de gewenste bijlage kunnen kiezen.

Maar is zoiets mogelijk via php, een mail + bijlage on line ?

Dank.

Ja Zoek hier eens, weet bijna zeker dat er wat bijzit: http://www.phphulp.nl/

Thx bruno, die site kende ik (nog) niet. Helaas heb ik daar niet op gevonden.

Wel heb ik op een andere site iets gevonden, maar ik krijg een parse error op lijn 32

Kan iemand hem verhelpen ?

[code:1:a459454776]
<html>
<head>
<title><?php echo $pageTitle; ?></title>
<link rel="stylesheet" href="…/c/stijl.css">
</head><body>
<?
include ("…/conf.php");
$to = $listrow[email]; // ok
$from = $mailinglist_sender; //ok

$listquery = "SELECT naam, email FROM $gegevens";
$listresult = mysql_query($listquery);

while($listrow = mysql_fetch_array($listresult))
{

if ($action == "send")

{

$header = "From: " . $from . "n";

if ($attachement != "none")

{

// Maximum filesize in bytes

$max = "1500000";

// Permitted extentions, leave empty to permit all extentions

$ext = "";

// Get Filename

$bestand2 = explode("&quot;, $attachement_name);

$laatste = count($bestand2) - 1;

$bestand2 = "$bestand2[$laatste]";

// Get extention from file

$bestand3 = explode(".", $bestand2);

$laatste = count($bestand3) - 1;

$bestand3 = "$bestand3[$laatste]";

$bestand3 = strtolower($bestand3);

// Get Permitted extentions

$exten = $ext;

$ext = strtolower($ext);

$ext = explode(" ", $ext);

$aantal = count($ext);

for ($tel = 0;$tel < $aantal; $tel++)

{

if ($bestand3 == $ext[$tel])

{

$extfout = &quot;nee&quot;;  

}

}

if (!$extfout)

{

// No permittion for extention

print ("Can not send "$bestand2"!!! You can only send $exten-files!");

$stopmail="ja";

}

else

{

if ($bestand_size > $max)

{// File is to large

print&#40;&quot;The file &quot;$bestand2&quot; is bigger than $max bytes!&quot;&#41;; 

$stopmail=&quot;ja&quot;; 

}

else

{// Get attachement type

$type = $HTTP_POST_FILES&#91;attachement&#93;&#91;type&#93;;  

if &#40;&#40;$type == &quot;text/plain&quot;&#41; || &#40;$type == &quot;text/html&quot;&#41;&#41;  

 $encoding = &quot;8bit&quot;;  

else  

 $encoding = &quot;base64&quot;;  

// Get attachement content 

$fp = @fopen&#40;$HTTP_POST_FILES&#91;attachement&#93;&#91;tmp_name&#93;,&quot;r&quot;&#41;;  

if &#40;!$fp&#41; 

&#123;  

 print &quot;Could not open attachment for reading...&lt;br&gt;n&quot;;  

 print &quot;Exiting script!&lt;br&gt;&lt;br&gt;&quot;;  

 print &quot;No mail has been sent!&quot;;  

 exit;  

&#125; 

$file_content = fread&#40;$fp,filesize&#40;$HTTP_POST_FILES&#91;attachement&#93;&#91;tmp_name&#93;&#41;&#41;;  

// if encoding is base64 ... encode it 

if &#40;$encoding == &quot;base64&quot;&#41;  

 $file_content = chunk_split&#40;base64_encode&#40;$file_content&#41;&#41;;  

// create a unqiue boundary 

$boundary = strtoupper&#40;md5&#40;uniqid&#40;time&#40;&#41;&#41;&#41;&#41;;  

// create the message header... 

$header .= &quot;MIME-version&#58; 1.0n&quot;;  

$header .= &quot;Content-Type&#58; multipart/mixed;n&quot;;  

$header .= &quot;tboundary= &quot; . $boundary . &quot;nn&quot;;  

$header .= &quot;This is a multi-part message in MIME format.nn&quot;;  

// create the message body in the header 

$header .= &quot;--&quot; . $boundary . &quot;n&quot;;  

$header .= &quot;Content-Type&#58; &quot; . $ct . &quot;;n&quot;;  

$header .= &quot;tcharset=&quot;iso-8859-1&quot;n&quot;;  

$header .= &quot;Content-Transfer-Encoding&#58; quoted-printablenn&quot;;  

// actual message 

$header .=  $body . &quot;nn&quot;;  

// now for the attachement 

$header .= &quot;--&quot; . $boundary . &quot;n&quot;;  

$header .= &quot;Content-Type&#58; &quot; . $type . &quot;n&quot;;  

$header .= &quot;Content-Transfer-Encoding&#58; &quot; . $encoding . &quot;n&quot;;  

$header .= &quot;Content-Disposition&#58; attachment; filename=&quot;&quot; . $HTTP_POST_FILES&#91;attachement&#93;&#91;name&#93; . &quot;&quot;nn&quot;;  

// actual attachement 

$header .= $file_content . &quot;nn&quot;;  

$header .= &quot;--&quot; . $boundary . &quot;--&quot;; 

}

}

if(!$stopmail)

{

if (@mail($to,$subject,"",$header))

print &quot;Mail sent!&quot;;  

else

print &quot;Error sending email!&quot;;  

}

else

{

print "<br><a href=javascript:history.back()>Click here to go back</a>";

}

}

else // if there is no attachement…

{

$header .= "Content-Type: " . $ct . ";n";

$header .= "tcharset="iso-8859-1"n";

$header .= "Content-Transfer-Encoding: quoted-printablenn";

// actual message

$header .= $body . "nn";

if (@mail($to,$subject,"",$header))

print "Mail sent!";

else

print "Error sending email!";

}

}

else

{

?>

<form enctype="multipart/form-data" action="mail.php" method="POST">

<input type="hidden" name="action" value="send">

<table width="500" cellspacing="0" cellpadding="0" border="0">

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Subject&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;input type=&quot;text&quot; size=&quot;40&quot; name=&quot;subject&quot;&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Content type&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;select name=&quot;ct&quot;&gt; 

  &lt;option value=&quot;text/plain&quot;&gt;Plaintext&lt;/option&gt; 

  &lt;option value=&quot;text/html&quot;&gt;HTML mail&lt;/option&gt; 

&lt;/select&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="top">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Message body&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="top">

&lt;textarea rows=&quot;8&quot; cols=&quot;38&quot; name=&quot;body&quot;&gt;&lt;/textarea&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Attachement&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;input type=&quot;file&quot; name=&quot;attachement&quot;&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

&amp;nbsp; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;input type=&quot;submit&quot; value=&quot;Send&quot;&gt; 

</td>

</tr>
<tr><tD></td><td><a href="index.php">administratie index</a></td></tr>
</table>

</form>
<?

}
}
?>

</body>
</html>
[/code:1:a459454776]

En kijk anders even op [url]www.phpfreakz.nl[/url] daar barst het ook van de forums, scripts en artikelen! :)

Ik heb dus nl iets gevonden.

Maar, ik krijg een goed beeld van het emailform en als ik op verstuur druk dan krijg ik een internal server error.
Dus ik weet niet of het werkt ??
Wat doe ik fout ? CHMOD = 777

[code:1:2a1fede18e]
<html>
<head>
<title><?php echo $pageTitle; ?></title>
<link rel="stylesheet" href="…/c/stijl.css">
</head><body>
<?
include ("…/conf.php");
$to = $listrow[email]; // ok
$from = $mailinglist_sender; //ok

$listquery = "SELECT naam, email FROM $gegevens";
$listresult = mysql_query($listquery);

while($listrow = mysql_fetch_array($listresult))
{

if ($action == "send")

{

$header = "From: " . $from . "n";

if ($attachement != "none")

{

// Maximum filesize in bytes

$max = "1500000";

// Permitted extentions, leave empty to permit all extentions

$ext = "";

// Get Filename

$bestand2 = explode("&quot;, $attachement_name);

$laatste = count($bestand2) - 1;

$bestand2 = "$bestand2[$laatste]";

// Get extention from file

$bestand3 = explode(".", $bestand2);

$laatste = count($bestand3) - 1;

$bestand3 = "$bestand3[$laatste]";

$bestand3 = strtolower($bestand3);

// Get Permitted extentions

$exten = $ext;

$ext = strtolower($ext);

$ext = explode(" ", $ext);

$aantal = count($ext);

for ($tel = 0;$tel < $aantal; $tel++)

{

if ($bestand3 == $ext[$tel])

{

$extfout = &quot;nee&quot;;  

}

}

if (!$extfout)

{

// No permittion for extention

print ("Can not send "$bestand2"!!! You can only send $exten-files!");

$stopmail="ja";

}

else

{

if ($bestand_size > $max)

{// File is to large

print&#40;&quot;The file &quot;$bestand2&quot; is bigger than $max bytes!&quot;&#41;; 

$stopmail=&quot;ja&quot;; 

}

else

{// Get attachement type

$type = $HTTP_POST_FILES&#91;attachement&#93;&#91;type&#93;;  

if &#40;&#40;$type == &quot;text/plain&quot;&#41; || &#40;$type == &quot;text/html&quot;&#41;&#41;  

 $encoding = &quot;8bit&quot;;  

else  

 $encoding = &quot;base64&quot;;  

// Get attachement content 

$fp = @fopen&#40;$HTTP_POST_FILES&#91;attachement&#93;&#91;tmp_name&#93;,&quot;r&quot;&#41;;  

if &#40;!$fp&#41; 

&#123;  

 print &quot;Could not open attachment for reading...&lt;br&gt;n&quot;;  

 print &quot;Exiting script!&lt;br&gt;&lt;br&gt;&quot;;  

 print &quot;No mail has been sent!&quot;;  

 exit;  

&#125; 

$file_content = fread&#40;$fp,filesize&#40;$HTTP_POST_FILES&#91;attachement&#93;&#91;tmp_name&#93;&#41;&#41;;  

// if encoding is base64 ... encode it 

if &#40;$encoding == &quot;base64&quot;&#41;  

 $file_content = chunk_split&#40;base64_encode&#40;$file_content&#41;&#41;;  

// create a unqiue boundary 

$boundary = strtoupper&#40;md5&#40;uniqid&#40;time&#40;&#41;&#41;&#41;&#41;;  

// create the message header... 

$header .= &quot;MIME-version&#58; 1.0n&quot;;  

$header .= &quot;Content-Type&#58; multipart/mixed;n&quot;;  

$header .= &quot;tboundary= &quot; . $boundary . &quot;nn&quot;;  

$header .= &quot;This is a multi-part message in MIME format.nn&quot;;  

// create the message body in the header 

$header .= &quot;--&quot; . $boundary . &quot;n&quot;;  

$header .= &quot;Content-Type&#58; &quot; . $ct . &quot;;n&quot;;  

$header .= &quot;tcharset=&quot;iso-8859-1&quot;n&quot;;  

$header .= &quot;Content-Transfer-Encoding&#58; quoted-printablenn&quot;;  

// actual message 

$header .=  $body . &quot;nn&quot;;  

// now for the attachement 

$header .= &quot;--&quot; . $boundary . &quot;n&quot;;  

$header .= &quot;Content-Type&#58; &quot; . $type . &quot;n&quot;;  

$header .= &quot;Content-Transfer-Encoding&#58; &quot; . $encoding . &quot;n&quot;;  

$header .= &quot;Content-Disposition&#58; attachment; filename=&quot;&quot; . $HTTP_POST_FILES&#91;attachement&#93;&#91;name&#93; . &quot;&quot;nn&quot;;  

// actual attachement 

$header .= $file_content . &quot;nn&quot;;  

$header .= &quot;--&quot; . $boundary . &quot;--&quot;; 

}

}

if(!$stopmail)

{

if (@mail($to,$subject,"",$header))

print &quot;Mail sent!&quot;;  

else

print &quot;Error sending email!&quot;;  

}

else

{

print "<br><a href=javascript:history.back()>Click here to go back</a>";

}

}

else // if there is no attachement…

{

$header .= "Content-Type: " . $ct . ";n";

$header .= "tcharset="iso-8859-1"n";

$header .= "Content-Transfer-Encoding: quoted-printablenn";

// actual message

$header .= $body . "nn";

if (@mail($to,$subject,"",$header))

print "Mail sent!";

else

print "Error sending email!";

}

}

else

{

?>

<form enctype="multipart/form-data" action="mail.php" method="POST">

<input type="hidden" name="action" value="send">

<table width="500" cellspacing="0" cellpadding="0" border="0">

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Subject&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;input type=&quot;text&quot; size=&quot;40&quot; name=&quot;subject&quot;&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Content type&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;select name=&quot;ct&quot;&gt; 

  &lt;option value=&quot;text/plain&quot;&gt;Plaintext&lt;/option&gt; 

  &lt;option value=&quot;text/html&quot;&gt;HTML mail&lt;/option&gt; 

&lt;/select&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="top">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Message body&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="top">

&lt;textarea rows=&quot;8&quot; cols=&quot;38&quot; name=&quot;body&quot;&gt;&lt;/textarea&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

Attachement&#58; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;input type=&quot;file&quot; name=&quot;attachement&quot;&gt; 

</td>

</tr>

<tr>

<td width="150" align="left" valign="center">

&lt;font face=&quot;Verdana,Tahoma,Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#000000&quot;&gt; 

&amp;nbsp; 

&lt;/font&gt; 

</td>

<td width="350" align="left" valign="center">

&lt;input type=&quot;submit&quot; value=&quot;Send&quot;&gt; 

</td>

</tr>
<tr><tD></td><td><a href="index.php">administratie index</a></td></tr>
</table>

</form>
<?

}
}
?>

</body>
</html>
[/code:1:2a1fede18e]

De correcte syntax voor mail() is: mail($emailadres, $subject, $body, $headers );

Als ik zo vlot even door je script heenlees, zie ik dat je AL je data in de headers probeert te krijgen, en de body leeglaat.

Op Panther’s den vind je SimpleMailer.
Een goed voorbeeld om geuploade attachments te versturen