E-Mail mit Anhang verschicken

nero25

Mitglied
Hallo Freunde

Habe wieder ein Problem! Ich versuche noch immer
Mails mit Anhang zu verschicken mit folgendes Form:

<html>
<head>
<title></title>
</head>
<body>
<form action="test.php" method="post" enctype="multipart/form-data">
<br>Absender:
<br>
<input type="text" name="absender" maxlength="100">

<br>Betreff:
<br>
<input type="text" name="betreff" maxlength="100">

<br>Nachricht:
<br>
<textarea name="body" cols="30" rows="5"></textarea>

<br>Anhang:
<br>
<input type="file" name="file" maxlength="100">
<br><br>
<input type="submit" value="Senden">
</form>
</body>
</html>


und folgendem PHP-Scrpt:

<?php
function attach($empfaenger, $absender, $betreff, $body, $file)
{
$mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1));
$data = chunk_split(base64_encode(file_get_contents($file)));
$header = "From: ".$absender."\r\n";
$header.= "To: ".$empfaenger."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: multipart/mixed;\r\n";
$header.= " boundary=\"".$mime_boundary."\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n";

$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain"; #charset=\"iso-8859-1\"\r\n"
$content.= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$content.= $body."\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: image/*; name=\"".$file."\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--" . $mime_boundary . "\r\n";
if(mail($empfaenger, $betreff, $content, $header))
{
return TRUE;
}
echo "Fehler: " . $php_errormsg;
return FALSE;
}
$empfaenger = "reiminer@freenet.de";
$absender = "$absender";
$betreff = "$betreff";
$body = "$body";
$file = "$file";
ini_set('track_errors', 'On');
attach($empfaenger, $absender, $betreff, $body, $file);
?>

mittlerweile habe ich es immerhin soweit gebracht,
das die Mail bei mir landet.
Nur als Anhang kommt irgendeine komische leere txt datei
und folgende Fehlermeldung wird im Explorer ausgegeben:

Warning: file_get_contents() [function.file-get-contents]: open_basedir restriction in effect.
File(/tmp/phpWQbD5r) is not within the allowed path(s): (/home/www/htdocs/XXX-XXX.de/.)
in /home/www/htdocs/XXX-XXX.de/test/test.php on line 5

Warning: file_get_contents(/tmp/phpWQbD5r) [function.file-get-contents]:
failed to create stream: Operation not permitted in /home/www/htdocs/XXX-XXX.de/test/test.php
on line 5

kann mir da mal bittttte jemand helfen?

vielen Dank im voraus
 
Hi,

die Einstellungen Deines Webservers verhindern den Zugriff auf die Datei. Sprich er kann sie nicht öffnen um die Daten auszulesen. Die Datei müssen in folgendem Verzeichnis (,oder dessen Unterverzeichnisse) auf dem Webserver liegen:

/home/www/htdocs/XXX-XXX.de/

Dort liegt auch Deine test.php
 
Erst mal danke für die schnelle Antwort!

Die test.php habe ich im ordner test. jetzt habe ich die klamotten ins root-verzeichnis gepackt und es kam folgende meldung

Warning: file_get_contents() [function.file-get-contents]: open_basedir restriction in effect. File(/tmp/phpSTISEk) is not within the allowed path(s): (/home/www/htdocs/michael-murek.de/.) in /home/www/htdocs/XXXXX-XXXXX.de/test.php on line 5

Warning: file_get_contents(/tmp/phpSTISEk) [function.file-get-contents]: failed to create stream: Operation not permitted in /home/www/htdocs/XXXXX-XXXXX.de/test.php on line 5
 
Du machst vermutlich einen file-upload ? Dieser packt die hochgeladene Datei in das /tmp/-Verzei chnis (/tmp/phpSTISEk). Und darauf hast Du keinen Zugriff. Wie man das ändern kann weiß ich leider nicht. Das gehört zum Webserver. :(
 
Hallo Freunde, ich bins wieder!

Habe mir nun etwas neues zusammengebaut und haut leider auch nicht hin.
Hier mal das Formular:

<html>
<head>
<title></title>
</head>
<body>
<form action="sendmsg.php" method="post" enctype="multipart/form-data">
<br>Empfänger:
<br>
<input type="text" name="to" maxlength="100">

<br>Absender:
<br>
<input type="text" name="from" maxlength="100">

<br>Betreff:
<br>
<input type="text" name="subject" maxlength="100">

<br>Nachricht:
<br>
<textarea name="text" cols="55" rows="5"></textarea>

<br>Anhang:
<br>
<input type="file" name="file" maxlength="100">


<br>Bildtyp:
<br>
<select name="type" size="1">
<option value="Bild.gif">image.gif
<!--<option value="Bild.jpeg">Bild.jpeg -->
</select>


<br><br>
<input type="submit" value="Senden">
</form>
</body>
</html>



und hier das PHP-Script:


<?php
function sendmsg($to, $subject, $text, $from, $file, $type) {
$content = fread(fopen($file,"r"),filesize($file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$name = basename($file);

$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$uid\n";

$header .= "--$uid\n";
$header .= "Content-Type: text/plain\n";
$header .= "Content-Transfer-Encoding: 8bit\n\n";
$header .= "$text\n";

$header .= "--$uid\n";

$header .= "Content-Type: image/gif; name=\"$name\"\n";
#$header .= "Content-Type: $type; name=\"$name\"\n";

$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"$name\"\n\n";
$header .= "$content\n";

$header .= "--$uid--";

mail($to, $subject, "", $header);

return true;
}

/*An edit to run this script if a form has been submitted*/

if ($_POST) {

$to1 = $_POST['to'];
$subject1 = $_POST['subject'];
$text1 = $_POST['text'];
$from1 = $_POST['from'];
$file1 = $_POST['file'];
$type1 = $_POST['type'];

sendmsg($to1, $subject1, $text1, $from1, $file1, $type1);

}
?>


wieder kommt die mail beir mir an, aber der Anhang ist
eine Att00019.gif(0 Byte) datei und nicht xxx.gif

die Fehlermeldung lautet diesmal:


Warning: filesize() [function.filesize]: Unable to access in /home/www/htdocs/michael-murek.de/test/sendmsg.php on line 3

Warning: fread(): supplied argument is not a valid stream resource in /home/www/htdocs/michael-murek.de/test/sendmsg.php on line 3

werde einfach nicht schlau aus der Sache

bitte hiiiilfe


gruß
 
Hallo,

versuch mal das was ich hier habe. Damit kannst du auch Mails mit Anhang verschicken.

Das was nun kommt das muss ganz an den Anfang deiner Datei:

PHP:
<?php
$max_attach_size = 500000;
?>

So das was nun kommt ist das Formular mit dem Code. Das kannst du an jede belibige Stelle auf deiner Seite einsetzten!

PHP:
<?php
if (isset($_POST["form_submitted"]))
 {
  // &uuml;bergebene Variablen ermitteln:
 $mailadressen = array();
 $mailadressen["Feedback"] = "deine Mail Adresse";
 $mailadressen["Info"] = "eine Mail Adresse";
 $name = $_POST["vorname"]." ".$_POST["name"];
 $email = $_POST["email"];
 $subject = $_POST["subject"];
 $text = $_POST["text"];
if(isset($mailadressen[$_POST["mailto"]])) {
   $mailto = $mailadressen[$_POST["mailto"]];
} else {
   die("Keinen g&uuml;ltigen Empf&auml;nger ausgew&auml;hlt!");
} 
  // &Uuml;berpr&uuml;fungen der Daten:
  unset($errors);
  if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "die E-Mail-Adresse sieht nicht richtig aus";
  if ($text == "") $errors[] = "es wurde kein Text eingegeben";
  if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Attachment zu gro&szlig; (".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - Maximalgr&ouml;&szlig;e: ".number_format($max_attach_size/1000,0,",","")." KB";

  if (empty($errors))
   {
    $text = stripslashes($text);
    $subject = stripslashes($subject);
    if ($name != "") $mail_name=$name; else $mail_name="unbekannt";
    if ($subject != "") $mail_subject = $subject; else $mail_subject = "kein Betreff";
    if ($email != "") $mail_email = $email; else $mail_email = "deine Mail Adresse";
    $ip = $_SERVER["REMOTE_ADDR"];

    // Wenn Attachment, dann MIME-Mail erstellen:
    if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "")
     {
      // Datei einlesen und codieren:
      $datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),filesize($_FILES['probe']['tmp_name']));
      $datei_content = chunk_split(base64_encode($datei_content),76,"\n");

      // Boundary festlegen:
      $boundary = md5(uniqid(rand()));

      // Mail-Header:
      $mail_header = "From: ".$mail_name." <".$mail_email.">\n";
      $mail_header .= "X-Sender-IP: ".$ip."\n";
      $mail_header .= "MIME-Version: 1.0\n";
      $mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
      $mail_header .= "This is a multi-part message in MIME format.\n";
      // Mail-Text:
      $mail_header .= "--".$boundary;
      $mail_header .= "\nContent-Type: text/plain";
      $mail_header .= "\nContent-Transfer-Encoding: 8bit";
      $mail_header .= "\n\n".$text;
      // Attachment:
      $mail_header .= "\n--".$boundary;
      $mail_header .= "\nContent-Type: ".$_FILES['probe']['type']."; name=\"".$_FILES['probe']['name']."\"";
      $mail_header .= "\nContent-Transfer-Encoding: base64";
      $mail_header .= "\nContent-Disposition: attachment; filename=\"".$_FILES['probe']['name']."\"";
      $mail_header .= "\n\n".$datei_content;

      // Ende:
      $mail_header .= "\n--".$boundary."--";
      // Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
      if (@mail($mailto,$mail_subject,"",$mail_header)) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
     }
    // kein Attachment, normale E-Mail:
    else
     {
      $mail_header = "From: ".$mail_name." <".$mail_email.">\n";
      $mail_header .= "X-Sender-IP: $ip\n";
      $mail_header .= "Content-Type: text/plain";
      if (@mail($mailto,$mail_subject,$text,$mail_header)) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
     }

    // Kopie an Absender:
    if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
     {
      if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text;
      $header= "From: ".$mailto."\n";
      $header .= "X-Sender-IP: ".$ip."\n";
      $header .= "Content-Type: text/plain";
      @mail($email, $mail_subject, $copy_mail_text, $header);
     }
   }
 }

if (empty($sent))
 {
  if(isset($errors))
   {
    ?>
                                          <p align="left" class="caution">Fehler:</p>
                                          <div align="left">
                                            <ul>
                                              <?php foreach($errors as $f) { ?>
                                              <li><?php echo $f; ?></li>
                                              <?php } ?>
                                            </ul>
                                            <br />
                                            <?php
   }

  ?>
                                          </div>
                                          <form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
                                            <div>
                                              <div align="left">
                                                <table width="100%"  border="0">
                                                  <tr>
                                                    <td width="23%" height="25"><p>Name: </p></td>
                                                    <td width="77%"><p>
                                                        <input name="name" type="text" class="chatfields" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="32" maxlength="255" />
                                                    </p></td>
                                                  </tr>
                                                  <tr>
                                                    <td height="29"><p>E-Mail: </p></td>
                                                    <td><p>
                                                        <input name="email" type="text" class="chatfields" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="32" maxlength="255" />
                    (dahin geht die Antwort) </p></td>
                                                  </tr>
                                                  <tr>
                                                    <td height="27"><p>Betreff:</p></td>
                                                    <td><p><b>
                                                        <input name="subject" type="text" class="chatfields" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="40" maxlength="40" />
                                                    </b></p></td>
                                                  </tr>
                                                  <tr>
                                                    <td height="28">
                                                      <p>Art der Anfrage :</p></td>
                                                    <td><p><b>
                                                      <select name="mailto" class="chatfields">
                                                        <option>-- bitte ausw&auml;hlen --</option>
                                                        <option value="Feeback" selected>Werbung</option>
                                                        <option value="Info">Support</option>
                                                                                                            </select>
</b></p></td>
                                                  </tr>
                                                  <tr>
                                                    <td height="105"><p>Nachricht: </p></td>
                                                    <td><p>
                                                        <textarea name="text" cols="75" rows="6" class="chatfields"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?>
                                                    </textarea>
                                                    </p></td>
                                                  </tr>
                                                  <tr>
                                                    <td><p>Attachment: </p></td>
                                                    <td><p>
                                                        <input name="probe" type="file" class="chatfields" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="20"/>
                                                    </p></td>
                                                  </tr>
                                                </table>
                                              </div>
                                              <p align="left">
                                                <input name="form_submitted" type="submit" class="chatfields" value="&gt;&gt;&gt; Absenden" />
                                                <input type="checkbox" name="copy" value="true" />
            Kopie an Absender</p>
                                            </div>
                                          </form>
                                          <?php
 }
else
 {
  if (empty($email)) { ?>
                                          <p align="left"><b>Danke!</b><br />
        Nachricht erfolgreich versendet. Allerdings wurde keine E-Mail-Adresse angegeben, ich kann also nicht antworten.</p>
                                          <?php }
  else { ?>
                                          <p align="left"><b>Danke!</b><br />
        Nachricht erfolgreich versendet.</p>
                                          <?php }
 }

?>

Gruß BlackLove2005
 
Vielen Dank für die schnelle Antwort
Da ist aber noch ein Prob

Ich bekomme immer folgende Meldung

Keinen gültigen Empfänger ausgewählt

$mailadressen = array();
$mailadressen["Feedback"] = "Hier habe ich meine Adr. eingegeben"; <<<<<<<<<<
$mailadressen["Info"] = "eine Mail Adresse";
$name = $_POST["vorname"]." ".$_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$text = $_POST["text"];
 
Hallo,

hast du denn hier:

PHP:
$mailadressen["Feedback"] = "Hier habe ich meine Adr. eingegeben"; <<<<<<<<<<
$mailadressen["Info"] = "eine Mail Adresse";

überall deine Mail Adresse eingegeben:

das sollte dann z.B. so aussehen:

PHP:
$mailadressen["Feedback"] = "blacklove88@gmx.de";
$mailadressen["Info"] = "blacklove88@gmx.de";

Dann sollte das auch gehen.

Gruß BlackLove2005
 
nützt nix, habe jetzt überall meine mail-adresse eingegeben und die antwort ist

keinen gültigen empfänger angegeben
 

Neue Beiträge

Zurück