You are not logged in.

  • Login

1

Monday, October 30th 2006, 1:50pm

base64 decoding im Mailanhang

servus gemeinde,

ich hab folgendes problem:

ich hab ein skript für ein emailformular mit anhang erstellt. ich bekomme zwar ne mail, in der ist aber noch der base64-code zu sehen.
php ist nicht gerade meine stärke.
wo muss denn diese decoder-funktion hin?

also mein skript bi hierhin:

PHP Quellcode

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
function sendApplication( $id )
{
global $database, $mosConfig_absolute_path, $mosConfig_live_site, $option, $cfgjl, $mainframe, $my, $Itemid;
 
$row = new mosJobPosting( $database );
$row->load( $id );
 
if ( !$row->id )
{
mosRedirect( "$mosConfig_live_site/index.php?option=$option&task=error&msg=" . _JL_NOSUCHJOB );
}
else
{
$tmplvars = get_object_vars( $row );
foreach ( $_REQUEST as $k => $v )
{
$tmplvars["req_$k"] = $v;
}
 
$tmpl = new mxTemplate( "$mosConfig_absolute_path/components/com_jobline/templates/{$cfgjl['template']}" );
if ( $tmpl->setTemplate( "applicationemail" ) )
{
// store the file information to variables for easier access
$tmp_name= $_FILES['attach']['tmp_name'];
$type = $_FILES['attach']['type'];
$name = $_FILES['attach']['name'];
$size = $_FILES['attach']['size'];
$error = $_FILES['attach']['error'];
 
$message = '';
$mime_boundary = '';
 
$tmpl->setVars( $tmplvars );
$tmpl->parseTemplate();
$message = $tmpl->getOutput();
 
//echo '<br>--<br> 1.' . $message;
// if the upload succeded, the file will exist
if ( file_exists($tmp_name) )
{
//echo '<br>--<br> 2.' . $message;
// generate a random string to be used as the boundary marker
$mime_boundary = "--==Multipart_Boundary_x".md5(mt_rand())."x";
 
 
// check to make sure that it is an uploaded file and not a system file
if( is_uploaded_file($tmp_name) )
{
//echo '<br>--<br> 3.' . $message;
$message .= "nn Attachment : $name";
 
// open the file for a binary read
$file = fopen( $tmp_name,'rb' );
 
// read the file content into a variable
$data = fread( $file,filesize($tmp_name) );
 
// close the file
fclose( $file );
 
// now we encode it and split it into acceptable length lines
$data = chunk_split( base64_encode($data) );
}
 
 
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
 
$message = "This is a multi-part message in MIME format.\n" . "--{$mime_boundary}\n" .
"Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 8bit\n\n" . $message . "\n\n";
 
 
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
if( $data )
{
$message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" .
"name=\"{$name}\"\n" .
        "Content-Disposition: attachment;\n" .
        "filename=\"{$name}\"\n" .
        "Content-Transfer-Encoding: base64\n\n" . 
 
        $data . "\n\n";
}
$message .= "--{$mime_boundary}--\n";
}
 
//echo '<br>--<br> <b>4.</b>' . $message;
 
//$Replyto = '';
 
// function 
//sendEmail( $email, $subject, $message, $fromname, $fromemail, $replyto, $mime_boundary );
sendEmail( $cfgjl['mailfromaddress'], _JL_APPLICATION_SUBJECT, $message, $cfgjl['mailfromname'], $cfgjl['mailfromaddress'], $Replyto, $mime_boundary);
 
mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=thankyou&id=$id" );
}
else
{
showError( _JL_ERRORSETTMPL . ": applicationemail" );
}
 
}
 
}
 
 
 
 
function sendEmail( $email, $subject, $message, $fromname='', $fromemail='', $replyto='', $mime_boundary='')
{
/*if ( function_exists( "mosMail" ) )
{
mosMail($fromemail, $fromname, $email, $subject, $message);
}
else
{*/
// generate a random string to be used as the boundary marker
 
$headers = "";
if ( trim( $fromemail ) )
{
$headers = "From: $fromname <$fromemail>\r\n";
}
 
if ( trim( $replyto ) )
{
$headers .= "Reply-To: <$replyto>\r\n";
}
 
 
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Low\r\n";
$headers .= "X-Mailer: PHP 4.x \r\n";
 
if( $mime_boundary )
{
$headers .= "MIME-Version: 1.0\r\n".
"Content-Type: multipart/mixed;\n\t boundary=\"$mime_boundary\"";
}
 
@mail($email, $subject, $message, $headers); 
//}
}




danke schon mal im voraus.

:shock:

2

Monday, October 30th 2006, 2:10pm

du könntest natürlich einfach die methode base64_encode aus zeile 62 und das Content-Transfer-Encoding: base64 aus 85 entfernen

aber nach RFC 2045 sollte das eigentlich korrekt sein

3

Monday, October 30th 2006, 2:33pm

ja komisch

hab das auch schon andere meinungen einheolt und die meinten, dass das eihentlich funzen sollte.

hier mal mein formular.... vielleicht hab ich da was übersehen...

HTML Code

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
<form action="index2.php" method="POST" name="adminForm" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{mxtvalue=id}" />
    <input type="hidden" name="reference" value="{mxtvalue=reference}" />
    <input type="hidden" name="option" value="{mxtvalue=option}" />
    <input type="hidden" name="Itemid" value="{mxtvalue=Itemid}" />
    <input type="hidden" name="task" value="send" />
 
<table cellpadding="5" cellspacing="0" border="0" width="100%" class="contentpane">
	  <tr>
	    <td class="contentheading" width="100%" colspan="2">{mxtlang=_JL_APPLYFORJOB}: {mxtvalue=title} <br></td>
	  </tr>
      <tr>
        <td><b>{mxtlang=_JL_FIRSTNAME}</b></td>
		<td><input type="text" name="firstname" class="inputbox" size="40" value="" /></td>
      </tr>
      <tr>
        <td><b>{mxtlang=_JL_LASTNAME}</b></td>
		<td><input type="text" name="lastname" class="inputbox" size="40" value="" /></td>
      </tr>
      <tr>
        <td><b>{mxtlang=_JL_ADDRESS1}</b></td>
		<td><input type="text" name="address1" class="inputbox" size="40" value="" /></td>
      </tr>
           <tr>
        <td><b>{mxtlang=_JL_CITY}</b></td>
		<td><input type="text" name="city" class="inputbox" size="40" value="" /></td>
      </tr>
{mxtshowif=config_useusstate}
      <tr>
        <td><b>{mxtlang=_JL_STATE}</b></td>
		<td>{mxtvalue=usstates}</td>
      </tr>
{/mxtshowif}
      <tr>
        <td><b>{mxtlang=_JL_ZIPCODE}</b></td>
		<td><input type="text" name="zipcode" class="inputbox" size="40" value="" /></td>
      </tr>
      <tr>
        <td><b>{mxtlang=_JL_DAYTELEPHONE}</b></td>
		<td><input type="text" name="daytelephone" class="inputbox" size="40" value="" /></td>
      </tr>
      <tr>
        <td><b>{mxtlang=_JL_EVENINGTELEPHONE}</b></td>
		<td><input type="text" name="eveningtelephone" class="inputbox" size="40" value="" /></td>
      </tr>
      <tr>
        <td><b>{mxtlang=_JL_APPLICANTEMAIL}</b></td>
		<td><input type="text" name="email" class="inputbox" size="40" value="" /></td>
      </tr>
      <tr>
        <td valign="top"><b>{mxtlang=_JL_COVER_LETTER}</b></td>
		<td><textarea class="inputbox" name="coverletter" id="coverletter" cols="50" rows="10"></textarea></td>
      </tr>
<tr>
<td valign="top"><b>Upload</b></td>
<td><input type="file" class="inputbox" name="attach" />
</td>
 
</tr>
      <tr>
        <td colspan="2"><input type="submit" name="sendbtn" class="button" value="{mxtlang=_JL_SEND_APPLICATION}"/></td>
      </tr>
    </table>
  </form>

4

Monday, October 30th 2006, 2:36pm

Ich dachte Mails sollten MIME encoded sein, aber gut...
Lade dir den PhpMailer runter - der sollte das hinkriegen.

5

Monday, October 30th 2006, 2:44pm

geht nicht

mal ne frage zum verständnis. muss denn encoded anhang überhaupt im skript wieder decoded werden? macht das nicht das email-programm des empfängers?

6

Monday, October 30th 2006, 3:10pm

mit dem genauen aufbau von mails kenne ich mich auch nicht aus
aber wenn du sowieso nicht so erfahren bist mit php, dann verwende einfach den phpMailer

hier ein howto: Webmailer mit PHP

7

Monday, October 30th 2006, 3:15pm

das problem ist ja, dass diese mailfunktion mit einer stellendatenbank verknüpft ist. es werden werte übernommen und übergeben etc...

also den phpmailer dann noch einzubauen, halte ich für nocht gewagter...
oder hab ich nen denkfehler?

8

Monday, October 30th 2006, 3:29pm

phpmailer ist simpel

ich würd mal behaupten, dass folgender code zu deiner obigen funktion äquivalent ist (vorausgesetzt er funktioniert)

PHP Quellcode

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
global $database, $mosConfig_absolute_path, $mosConfig_live_site, $option, $cfgjl, $mainframe, $my, $Itemid;
 
require("class.phpmailer.php");
$mail = new PHPMailer();
 
$row = new mosJobPosting( $database );
$row->load( $id );
 
if(!$row->id) {
	mosRedirect( "$mosConfig_live_site/index.php?option=$option&task=error&msg=" . _JL_NOSUCHJOB );
	return;
}
 
$tmplvars = get_object_vars( $row );
foreach ( $_REQUEST as $k => $v ) {
	$tmplvars["req_$k"] = $v;
}
 
$tmpl = new mxTemplate( "$mosConfig_absolute_path/components/com_jobline/templates/{$cfgjl['template']}" );
if ( !$tmpl->setTemplate( "applicationemail" ) ) {
	showError( _JL_ERRORSETTMPL . ": applicationemail" );
	return;
}
 
// store the file information to variables for easier access
$tmp_name= $_FILES['attach']['tmp_name'];
$name = $_FILES['attach']['name'];
 
$tmpl->setVars( $tmplvars );
$tmpl->parseTemplate();
$message = $tmpl->getOutput();
 
if ( file_exists($tmp_name) ) {
	$mail->AddAttachment($name);
}
 
$mail->AddAddress("josh@site.com", "Josh Adams");
$mail->From     = $cfgjl['mailfromaddress'];
$mail->FromName = $cfgjl['mailfromname'];
$mail->Subject  = _JL_APPLICATION_SUBJECT;
$mail->Body	= $message;
$mail->Send();
 
mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=thankyou&id=$id" );


nicht vergessen die class.phpmailer.php herunterzuladen und zu entpacken

9

Monday, October 30th 2006, 4:58pm

joomla

wie du vielleicht schon gesehen hast, arbeite ich hier mit jomla.

den phpmailer kann ich doch nicht über joomla installieren oder?

10

Monday, October 30th 2006, 5:17pm

Du musst ihn einfach nur includen - nix konfigurieren etc.
Einfach "require_once" und die Sache hat sich.

Similar threads

Social bookmarks