PHP Datei zum versenden von Anhang mit Kontaktformular
zwoemti
- php
Hallo ich benutze ein Programm zum Website erstellen nennt sich
INCOMEDIA WEBSITE X5
Ich habe ein Problem beim versenden eines kontaktformulars mit Anhang.
Es ist ein generelles Problem bei dem Programm so wie mir geht es noch anderen. da ich aber keine Lösung bzw. Hilfe im dazugehörigen Forum finde, wollte ich mal hier fragen ob jemand von euch erkennt wieso keine Anhänge mit verschickt werden.
Desweiteren wird als absender adresse immer meine email adresse angezeigt ist es möglich dies zu ändern?
Ich habe nicht allzuviel ahnung von der Sache aber vielleicht kann mir trotzdem jemand helfen.
Hier der Code, ich hoffe es ist erlaubt den hier zu posten ansonsten bitte löschen.
<?php
//Incomedia WebSite X5 EMail Class. All rights reserved.
//true = force the user email address to be set as the sender
$imForceSender = false;
class imEMail {
var $from;
var $to;
var $subject;
var $charset;
var $text;
var $html;
var $attachments;
function imEMail($from,$to,$subject,$charset) {
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->charset = $charset;
}
function setFrom($from) {
$this->from = $from;
}
function setTo($to) {
$this->to = $to;
}
function setSubject($subject) {
$this->subject = $subject;
}
function setCharset($charset) {
$this->charset = $charset;
}
function setText($text) {
$this->text = $text;
}
function setHTML($html) {
$this->html = $html;
}
function attachFile($name,$content,$mime_type) {
$attachment['name'] = $name;
$attachment['content'] = base64_encode($content);
$attachment['mime_type'] = $mime_type;
$this->attachments[] = $attachment;
}
function send() {
$headers = "";
$msg = "";
if($this->from == "" || $this->to == "" || ($this->text == "" && $this->html == ""))
return false;
$boundary = md5(time());
$headers .= "From: " . $this->from . "\n";
$headers .= "Message-ID: <" . time() . rand(0,9) . rand(0,9) . "@websitex5.users>\n";
$headers .= "X-Mailer: WebSiteX5 Mailer\n";
$headers .= "MIME-Version: 1.0\n";
if(is_array($this->attachments)) {
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $boundary . "\"\n\n";
$headers .= "--" . $boundary . "\n";
}
if($this->html == "") {
$headers .= "Content-Type: text/plain; charset=" . $this->charset . "\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$msg .= $this->text . "\n\n";
}
else if($this->text == "") {
$headers .= "Content-Type: text/html; charset=" . $this->charset . "\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$msg .= $this->html . "\n\n";
}
else {
$alt_boundary = $boundary . "_alt";
$headers .= "Content-Type: multipart/alternative; boundary=\"" . $alt_boundary . "\"\n";
$msg .= "--" . $alt_boundary . "\n";
$msg .= "Content-Type: text/plain; charset=" . $this->charset . "\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $this->text . "\n\n";
$msg .= "--" . $alt_boundary . "\n";
$msg .= "Content-Type: text/html; charset=" . $this->charset . "\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $this->html . "\n\n";
$msg .= "--" . $alt_boundary . "--\n\n";
}
if(is_array($this->attachments)) {
foreach($this->attachments as $attachment) {
$msg .= "--" . $boundary . "\n";
$msg .= "Content-Type: " . $attachment["mime_type"] . "; name=\"" . $attachment["name"] . "\"\n";
$msg .= "Content-Transfer-Encoding: base64\n";
$msg .= "Content-Disposition: attachment; filename=\"" . $attachment["name"] . "\"\n\n";
$msg .= chunk_split($attachment["content"]) . "\n\n";
}
$msg .= "--" . $boundary . "--\n\n";
}
$r = @mail($this->to, $this->subject, $msg, $headers, "-f" . $this->from);
if(!$r) {
$headers = "To: " . $this->to . "\n" . $headers;
$r = @mail($this->to, $this->subject, $msg, $headers);
}
return $r;
}
}
?>
Hello,
auf welcher Plattform wird das Script eingesetzt?
OS:
Mailserver:
Als erstes habe ich bei nicht verschicktem Anhang immer die Funktion chunk_split in Verdacht, wenn das Script die zu versendende Mail auf einem Linux-Host per Shellscript (sendmail) versendet
$msg .= chunk_split($attachment["content"]) . "\n\n";
## http://de3.php.net/manual/en/function.chunk-split.php
Es muss dann als Stringend-Parameter ein "\n" angegeben werden, da die "\r\n", die default sind, das Sendmail-Script durcheinander bringen.
Liebe Grüße aus dem schönen Oberharz
Tom vom Berg
Mahlzeit zwoemti,
Ich habe ein Problem beim versenden eines kontaktformulars mit Anhang.
Was genau bewirkt diese Methode Deiner Meinung nach?
function attachFile($name,$content,$mime\_type) { $attachment['name'] = $name; $attachment['content'] = base64\_encode($content); $attachment['mime\_type'] = $mime\_type; $this->attachments[] = $attachment; }
Wie sehen das (HTML-)Kontaktformular und das PHP-Skript, an das dieses Formular zur Verarbeitung geschickt wird, aus? Werden die eingegebenen Daten überhaupt korrekt verarbeitet? Kommen die hochgeladenen Dateien überhaupt auf dem Server an?
Desweiteren wird als absender adresse immer meine email adresse angezeigt ist es möglich dies zu ändern?
Was genau bewirken diese beiden Methoden Deiner Meinung nach?
function imEMail($from,$to,$subject,$charset) { $this->from = $from; $this->to = $to; $this->subject = $subject; $this->charset = $charset; } function setFrom($from) { $this->from = $from; }
Es fehlen haufenweise relevante Informationen - liefere diese nach.
MfG,
EKKi