PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



Emailform with attachment

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General
View previous topic :: View next topic  
Author Message
Pad



Joined: 04 Oct 2004
Posts: 30

PostPosted: Mon Nov 08, 2004 4:43 pm    Post subject: Emailform with attachment Reply with quote

I want to create a form which sends an email to an account. Creating this isnt the hard part, its trying to insert an attachment.

I created a form file with all needed attributes and so <input type="file" name="imgfile"> to upload an image.

My process form looks like this and works perfectly with only one problem. The image isnt attached, I only get to see its location an my PC.

[code:1]<?php

// get posted data into local variables
$EmailFrom = Trim($_POST[EmailFrom]);
$EmailTo = "emailadres";
$Subject = Trim($_POST[Subject]);
$Naam = Trim($_POST[Naam]);
$imgfile = Trim($_POST[imgfile]);

// validation
$validationOK=true;
if (Trim($EmailFrom)=="" OR Trim($_POST[Subject])=="" OR $Naam = Trim($_POST[Naam])=="" OR $imgfile = Trim($_POST[imgfile])=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "$Naam ";
$Body .= "zou graag zijn evenement $Subject in de kijker plaatsen";
$Body .= "\n";
$Body .= "Hij geeft hiervoor $Prijs";
$Body .= "\n";
$Body .= "$imgfile";
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=succes.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
?>[/code:1]

Any idea´s?

I also tried with $_FILES but that just gave me the location on my server without the file
[code:1]$uploaddir = '/path/to/your/image/files/'; // remember the trailing slash!
$uploadfile = $uploaddir. $_FILES['imgfile'];
[/code:1]
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 6059
Location: toronto, canada

PostPosted: Mon Nov 08, 2004 6:50 pm    Post subject: Reply with quote

The email is sent from the serverl. Any file to be attached to the email needs to be on the server as well, so you need to upload the file, send the email and then delete the file, if you want to.
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum