5, December 2008

Hello frtom Bob - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  WebDigity Community  >  Forum Lounge  >  New Member Introductions
Topic: Hello frtom Bob
« previous next »
Pages: [1] Print

Author Topic: Hello frtom Bob  (Read 547 times)
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« on: Jan 05, 2007, 08:52:49 PM »

Hi,

I'm 73 and retired.

Looking for code to add to a web site that will allow the user to send a message and an attachment via email.

I have the php, etc that will send email but can't find the code to send an attachment.

Or at least one that I can understand how to install.

I've been looking at "upload_class.php" but the installation instructions seem either vague or missing.

TIA,
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #1 on: Jan 05, 2007, 10:36:24 PM »

Hi Bob! Welcome to the forums.

How much do you know about php and what is it exactly that you want to do? Do you only need the attachment uploaded and the mail send to you with a link to the uploaded file, or do you need it to be send allong as an attachment with the mail?

(Normally the first advise would be to get used to php a bit, so you can fully understand premade scripts and be able to modify them, but at 73 I'm not sure how good this advise would be... Wink )
« Last Edit: Jan 05, 2007, 10:38:10 PM by Mind_nl »


Last blog : Are You Stumbling Yet?
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« Reply #2 on: Jan 05, 2007, 10:47:53 PM »

I'm not too familiar with php yet. I get along with simple statements.

What I want to do is;
               <input type="submit" value="Send File" />
               <input type="submit" value="Submit Application" />

with one button.

And then send the Application (form data) AND the attached file to my email address.
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #3 on: Jan 05, 2007, 11:12:14 PM »

You can find a bit more about e-mailing with php here Visit through proxy on page 5 of the article they talk about sending attachments and there is a working script to download. I haven't tried the script myself, but it sounds like the kind of script you are looking for.


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #4 on: Jan 05, 2007, 11:51:33 PM »

Hi Bob and welcome aboard Smiley

I am glad for you, it needs a lot of courage to start with a programming language at your age, and in general programming is a tough thing (I am 26, working as a programmer, and I have decided to stop some time, hopefully before I damage my brain Smiley )

I can provide you with help on how to send an email with attachment, or even write a tutorial about that, but as I am really tired now I will leave it for tomorrow. In the meanwhile you can check this php class Visit through proxy which is capable to send emails with attachments.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« Reply #5 on: Jan 06, 2007, 08:12:43 PM »

Here is the .php I've got so far. Everything works except no attachment is sent. "fileatt_name" contains the file name.
Any suggestions?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Emailing Form Data</title>
<style type="text/css">
code {color:#F00C4D;
font-weight:bold;
font-size:1.2em}
i {color: #6D0CF0}
th, td {padding:.1em;border:1px solid blue;text-align:left}
a { color:blue;
text-decoration:underline;
font-weight:bold;
font-size:1.2em}
</style>
</head>
<body>
<?php
//This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the <code>name</code> attribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you've added it to the script).

function check_email_address($email_address) {
  
// First, we check that there's one @ symbol, and that the lengths are right
  
if (!ereg("^[^@]{1,64}@[^@]{1,255}$"$email_address)) {
    
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    
return false;
  }
  
// Split it into sections to make life easier
  
$email_address_array explode("@"$email_address);
  
$local_array explode("."$email_address_array[0]);
  for (
$i 0$i sizeof($local_array); $i++) {
     if (!
ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$"$local_array[$i])) {
      return 
false;
    }
  }  
  if (!
ereg("^\[?[0-9\.]+\]?$"$email_address_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    
$domain_array explode("."$email_address_array[1]);
    if (
sizeof($domain_array) < 2) {
        return 
false// Not enough parts to domain
    
}
    for (
$i 0$i sizeof($domain_array); $i++) {
      if (!
ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$"$domain_array[$i])) {
        return 
false;
      }
    }
  }
  return 
true;
}

if (
check_email_address($email_address)) {
  echo 
$email_address '<strong> is a valid email address.<strong>';
} else {
  echo 
$email_address '<strong> is not a valid email address.<br /><br />Please click the back arrow and input all the required fields.<strong>';
exit();
}

if (empty(
$_POST)) {
print "<p><strong>No data was submitted.<br /><br />Please click the back arrow and input all the required fields.</strong></p>";
print "</body></html>";
exit();
}

If(
trim($First)=="") { 
print "<p><strong>No First name was submitted.<br /><br />
Please click the back arrow and input all the required fields.</strong></p>"
;
print "</body></html>";
exit();
}

If(
trim($Last)=="") {
print "<p><strong>No Last name was submitted.<br /><br />
Please click the back arrow and input all the required fields.</strong></p>"
;
print "</body></html>";
exit();
}

if (
trim($email_address)=="") {
print "<p><strong>No eMail address was submitted.<br /><br />
Please click the back arrow and input all the required fields.</strong></p>"
;
print "</body></html>";
exit();
}

//Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
function clear_user_input($value) {
if (get_magic_quotes_gpc()) $value=stripslashes($value);
$valuestr_replace"\n"''trim($value));
$valuestr_replace"\r"''$value);
return $value;
}

$body ="Here is the data that was submitted:\n";

foreach (
$_POST as $key => $value) {
$key clear_user_input($key);
$value clear_user_input($value);
if ($key=='extras') {

if (is_array($_POST['extras']) ){
$body .= "$key: ";
$counter =1;
foreach ($_POST['extras'] as $value) {
//Add comma and space until last element
if (sizeof($_POST['extras']) == $counter) {
$body .= "$value\n";
break;}
else {
$body .= "$value, ";
$counter += 1;
}
}
} else {
$body .= "$key: $value\n";
}
} else {

$body .= "$key: $value\n";
}
}

$from    $_POST['email_address'];
$subject 'Job Application - '$Last ", " $First;

// Obtain file upload vars
$fileatt      $_FILES['fileatt']['tmp_name'];
$fileatt_type $_FILES['fileatt']['type'];
$fileatt_name $_FILES['fileatt']['name'];

$headers "From: $from";

if (
is_uploaded_file($fileatt)) {
  
// Read the file to be attached ('rb' = read binary)
  
$file fopen($fileatt,'rb');
  
$data fread($file,filesize($fileatt));
  
fclose($file);

  
// Generate a boundary string
  
$semi_rand md5(time());
  
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
  
  
// Add the headers for a file attachment
  
$headers .= "\nMIME-Version: 1.0\n" .
              
"Content-Type: multipart/mixed;\n" .
              
" boundary=\"{$mime_boundary}\"";

  
// Add a multipart boundary above the plain message
  
$message "This is a multi-part message in MIME format.\n\n" .
             
"--{$mime_boundary}\n" .
             
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
             
"Content-Transfer-Encoding: 7bit\n\n" .
             
$message "\n\n";

  
// Base64 encode the file data
  
$data chunk_split(base64_encode($data));

  
// Add file attachment to the message
  
$message .= "--{$mime_boundary}\n" .
              
"Content-Type: {$fileatt_type};\n" .
              
" name=\"{$fileatt_name}\"\n" .
              
//"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              
"Content-Transfer-Encoding: base64\n\n" .
              
$data "\n\n" .
              
"--{$mime_boundary}--\n";
}

// Send the message
$ok = @mail('rpoland@usa.net'$subject$body$headers$message);

if (
$ok) {
  echo 
"<p>Mail was sent!</p>";
} else {
  echo 
"<p>Mail could not be sent. Sorry!</p>";
}
?>

</body>
</html>
« Last Edit: Jan 06, 2007, 08:39:41 PM by Mind_nl »
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5488
Tags : email an attachment Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  WebDigity Community  >  Forum Lounge  >  New Member Introductions
Topic: Hello frtom Bob
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Dec 05, 2008, 06:29:53 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.995
Total Topics: 7.685
Total Members: 4.468
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: sansthaa

29 Guests, 4 Users online :

10 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.