adding attachment to...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

dev2761:

Where is the file input field called "filename".

Also, you shouldn't really hijack someone elses thread.

Mark
User avatar
dev2761
Forum Newbie
Posts: 16
Joined: Thu Oct 16, 2003 7:55 am
Contact:

Post by dev2761 »

its here in the upload form:

Code: Select all

<input type='file' name='filename' accept='image/jpg'>
and please excuse me for "hijacking" but I have posted this elsewhere and it is some sort of follow up to the proposed problem.
Once again I'm sorry, please excuse me.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

but that isn't in the code you post a couple messages back
User avatar
dev2761
Forum Newbie
Posts: 16
Joined: Thu Oct 16, 2003 7:55 am
Contact:

Post by dev2761 »

No it is in the link, a couple of messages back, if you want I'll put all the code up for you to have a look or send it in a pm, whatever you want
ex247
Forum Commoner
Posts: 34
Joined: Tue Oct 28, 2003 1:35 am
Location: Boston, MA, USA
Contact:

Post by ex247 »

Code: Select all

function admin_send_msg() &#123;
 global $list_name, $list_file, $owner_email, $fileatt;
  set_time_limit(0);
 $subject = stripslashes($GLOBALS&#1111;subject]);
 $message = stripslashes($GLOBALS&#1111;message]);
 $subject = str_replace("%%", """, $subject);
 $message = str_replace("%%", """, $message); 

 $headers = "From: "$list_name" <$owner_email>
 			\r\nReply-To: $owner_email
			\r\nX-Sender: $owner_email
			\r\nX-UnsubscribeURL: http://$GLOBALS&#1111;'HTTP_HOST']$GLOBALS&#1111;'SCRIPT_NAME']
			\r\nX-Mailer: Newsletter v$GLOBALS&#1111;'version'] 
			\r\nX-AntiSpam: Newsletter did not send you this email, review below for sender info.
			\r\nX-AntiSpam: Sent by $GLOBALS&#1111;'REMOTE_ADDR']
			\r\n$attach
			r\n"\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary="&#123;$mime_boundary&#125;"";


 if ($GLOBALS&#1111;'SERVER_ADMIN']) $headers .= "X-AntiSpam: Server Administrator $GLOBALS&#1111;SERVER_ADMIN]\r\n"; 

 if ($GLOBALS&#1111;'use_sig'] == "on") $message .= $GLOBALS&#1111;'sig'];

 $sucess_count = 0;
 $fail_count = 0;

 $addresses = @file($list_file) or die("<center><b>The list data file could not be opened.</b><br>Check the path and permissions.</center>");
 $addresses&#1111;] = $owner_email;
 set_time_limit(0);
 foreach ($addresses as $email) &#123;
  $email = trim($email);
  if (mail($email, $subject, $message, $headers, $fileatt)) $sucess_count++;
  else $fail_count++;
 &#125;
 echo "<h3 align="center">Your message was sucessfully sent to $sucess_count addresses.</h3><h4 align="center">There was $fail_count unsucessfully sent.</h4>";
&#125;
thats what i have for the sendmail function... but whats wrong with it, it attaches a file, but just the filemakeup of it, not the actual file
ex247
Forum Commoner
Posts: 34
Joined: Tue Oct 28, 2003 1:35 am
Location: Boston, MA, USA
Contact:

Post by ex247 »

and i forgot to add that it doesnt send to some email accounts and i dont know why...
ex247
Forum Commoner
Posts: 34
Joined: Tue Oct 28, 2003 1:35 am
Location: Boston, MA, USA
Contact:

Post by ex247 »

i recoded most of it, but im still not getting the attachment sent. anyone heve any ideas about this?

Code: Select all

$subject = $_POST&#1111;'subject'];
$message = $_POST&#1111;'message'];

$uploadedfile = $_FILES&#1111;'uploadedfile'];
if (!$uploadedfile&#1111;'tmp_name']) &#123;
  $uploadedfile&#1111;'tmp_name'] = "/home/virtual/site3/fst/var/www/html/_work/maillist/uploads/noatt.txt";
  $uploadedfile&#1111;'name'] = "noatt.txt";
&#125;
$fileatt = $uploadedfile&#1111;'tmp_name']; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "$uploadedfile&#1111;'name']"; // Filename that will be used for the file as the attachment
$email_from = "$list_name"; // Who the email is from 
$email_subject = "$subject"; // The Subject of the email 
$email_message = "$message"; // Message that the email has in it 

$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb'); 
$data = fread($file,filesize($fileatt)); 
fclose($file); 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x&#123;$semi_rand&#125;x"; 
$headers .= "\nMIME-Version: 1.0\n" . 
            "Content-Type: multipart/mixed;\n" . 
            " boundary="&#123;$mime_boundary&#125;""; 
$email_message .= "This is a multi-part message in MIME format.\n\n" . 
                "--&#123;$mime_boundary&#125;\n" . 
                "Content-Type:text/html; charset="iso-8859-1"\n" . 
               "Content-Transfer-Encoding: 7bit\n\n" . 
               $email_message . "\n\n"; 
$data = chunk_split(base64_encode($data)); 
$email_message .= "--&#123;$mime_boundary&#125;\n" . 
                  "Content-Type: &#123;$fileatt_type&#125;;\n" . 
                  " name="&#123;$fileatt_name&#125;"\n" . 
                  //"Content-Disposition: attachment;\n" . 
                  //" filename="&#123;$fileatt_name&#125;"\n" . 
                  "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                  "--&#123;$mime_boundary&#125;--\n";

write message

Code: Select all

function admin_write_msg() &#123;
 global $username, $password, $owner_email, $list_name, $admin_keyword;
echo "
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="username" value="$username">
<input type="hidden" name="password" value="$password">
<input type="hidden" name="action" value="$admin_keyword">
<input type="hidden" name="q" value="send_msg_confirm">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<table align="center" border="0">
<tr><td colspan="2" align="center" valign="top"><font size="+1"><b>Send A Message:</b><br>&nbsp;</td></tr>
<tr><td align="left" valign="top"><b>From: </b></td><td align="left" valign="top">"$list_name" <$owner_email></td></tr>
<tr><td align="left" valign="top"><b>Subject: </b></td><td align="left" valign="top"><input type="text" name="subject" size="35"></td></tr>
<tr><td align="left" valign="top"><b>Message: </b></td><td align="left" valign="top"><textarea rows="15" cols="65" wrap="off" name="message"></textarea></td></tr>
<tr><td align="left" valign="top"><b>Attachment: </b></td><td align="left" valign="top"><input name="uploadedfile" type="file"></td></tr>
<tr><td></td><td align="left" valign="top"><input type="checkbox" checked name="use_sig"><font size="-1"><i>&nbsp;Append Signature</i></td></tr>
<tr><td></td><td align="left" valign="top"><input type="submit" value="Send">&nbsp;<input type="reset" value="Clear"></td></tr></table>
</form>";
&#125;

confirm message

Code: Select all

function admin_send_msg_confirm() &#123;
 global $username, $password, $subject, $message, $owner_email, $list_name, $list_file, $admin_keyword, $use_sig, $uploadedfile;
 $subject = stripslashes($subject);
 $message = stripslashes($message);
echo "
<form method="post">
<table align="center" border="0">
<tr><td colspan="2" align="center" valign="top"><font size="+1"><b>Please Confirm this is what you wish to send:</b><br>&nbsp;</td></tr>
<tr><td align="left" valign="top"><b>From: </b></td><td align="left" valign="top">"$list_name" <$owner_email></td></tr>
<tr><td align="left" valign="top"><b>Subject: </b></td><td align="left" valign="top">$subject</td></tr>
<tr><td align="left" valign="top"><b>Attachment: </b></td><td align="left" valign="top">$uploadedfile</td></tr>
<tr><td align="left" valign="top"><b>Message: </b></td><td align="left" valign="top"><pre>$message</pre></td></tr>";
 $subject = str_replace(""", "%%", $subject);
 $message = str_replace(""", "%%", $message);
echo"
<input type="hidden" name="username" value="$username">
<input type="hidden" name="password" value="$password">
<input type="hidden" name="message" value="$message">
<input type="hidden" name="subject" value="$subject">
<input type="hidden" name="uploadedfile" value="$uploadedfile">
<input type="hidden" name="use_sig" value="$use_sig">
<input type="hidden" name="action" value="$admin_keyword">
<input type="hidden" name="q" value="send_msg">
<tr><td></td><td align="left" valign="top"><input type="submit" value="Send">&nbsp;<input type="reset" value="Edit" OnClick="history.go(-1); return true;"></td></tr></table>
</form>";
&#125;

send message

Code: Select all

function admin_send_msg() &#123;
 global $list_name, $list_file, $owner_email;
  set_time_limit(0);
 $subject = stripslashes($GLOBALS&#1111;subject]);
 $message = stripslashes($GLOBALS&#1111;message]);
 $subject = str_replace("%%", """, $subject);
 $message = str_replace("%%", """, $message); 

$mime_boundary = "<<<--==+X&#1111;".md5(time())."]";

 if ($GLOBALS&#1111;'SERVER_ADMIN']) $headers .= "X-AntiSpam: Server Administrator $GLOBALS&#1111;SERVER_ADMIN]\r\n"; 

 if ($GLOBALS&#1111;'use_sig'] == "on") $message .= $GLOBALS&#1111;'sig'];

 $sucess_count = 0;
 $fail_count = 0;

 $addresses = @file($list_file) or die("<center><b>The list data file could not be opened.</b><br>Check the path and permissions.</center>");
 $addresses&#1111;] = $owner_email;
 set_time_limit(0);
 foreach ($addresses as $email) &#123;
  $email = trim($email);
  if (mail($email, $subject, $message, $headers)) $sucess_count++;
  else $fail_count++;
 &#125;
 echo "<h3 align="center">Your message was sucessfully sent to $sucess_count addresses.</h3><h4 align="center">There was $fail_count unsucessfully sent.</h4>";
&#125;
Post Reply