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:
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... )
« Last Edit: Jan 05, 2007, 10:38:10 PM by Mind_nl »
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:
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 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.
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8272
42619 credits Members referred : 3
« Reply #4 on: Jan 05, 2007, 11:51:33 PM »
Hi Bob and welcome aboard
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 )
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 which is capable to send emails with attachments.
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); $value= str_replace( "\n", '', trim($value)); $value= str_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 {