FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » CLP - ON TOPIC! - Need PHP form email help, Please!
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: CLP - ON TOPIC! - Need PHP form email help, Please! [message #173193 is a reply to message #173192] Sun, 27 March 2011 00:41 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 3/26/2011 6:32 PM, Tim wrote:
> In article<4d8c058d$0$29403$bed64819(at)gradwell(dot)net>, Denis McMahon
> <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote:
>
>> On Thu, 24 Mar 2011 15:26:21 -0500, Tim wrote:
>>
>>> In article<4d8b8eb6$0$995$bed64819(at)gradwell(dot)net>, Denis McMahon
>>> <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote:
>>>
>>>> On Thu, 24 Mar 2011 13:16:33 -0500, Tim wrote:
>>>>
>>>> > In article<4d8a5c0e$0$23756$14726298(at)news(dot)sunsite(dot)dk>, Jonathan
>>>> > Stein<jstein(at)image(dot)dk> wrote:
>>>> >
>>>> >> On 23-03-2011 19:05, Tim wrote:
>>>> >>
>>>> >>> I also find it strange, and very frustrating, that I seem to have
>>>> >>> to become a php expert just to make this one form page behave the
>>>> >>> way I want.
>>>>
>>>> >> http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-
>> in-
>>>> HTML-Em
>>>> >> ail-P113.html
>>>>
>>>> > I looked at that briefly. I hadn't searched for that exact string so
>>>> > I suppose that is why I hadn't seen it before.
>>>> >
>>>> > It is on the right track, though it would require a lot of
>>>> > modification to get it to work with my existing code since it uses an
>>>> > image located on the server and whose name is known.
>>>>
>>>> If you don't know what the file name of the image file is, how the heck
>>>> do you expect to be able to do anything at all with it?
>>>>
>>>> Perhaps your questions should start with:
>>>>
>>>> "How do I find out where the uploaded file is, and what it was called?"
>>>>
>>>> http://uk2.php.net/manual/en/reserved.variables.files.php
>>>>
>>>> After you have absorbed that information, perhaps you will then be
>>>> ready to ask "How do I use PHP to email this uploaded image to someone
>>>> else?"
>>
>>> Thanks for the concern, but I already have the form and handler code
>>> that gets the file's name. I was just pointing out that the example at
>>> that link was using a pre-existing image file, rather than an uploaded
>>> one, and hard-coding it into the script.
>>
>> Yes, and? You simply have to write code that uses your filename wherever
>> that code uses the hardcoded filename. It's not difficult.
>>
>>> This is all about getting the data, including the image, to me in the
>>> desired format so I can print it out without needing to make
>>> modifications to it such as placing the attached image where I want it.
>>
>> ok, maybe the second question should have been:
>>
>> "How do I use PHP to email this uploaded image to someone?"
>>
>> where "someone" might include yourself.
>>
>> Here's what happens:
>>
>> File is uploaded in a form. It gets put in a temporary location. The
>> $_FILES superglobal contains:
>>
>> a) original filename from uploading system
>> b) mime type
>> c) temporary name
>> d) status
>> e) size
>>
>> (possibly not in that order)
>>
>> mime type might not be valid, there's a suggestion it's supplied by the
>> uploader. original filename might also not be valid.
>>
>> First of all you should use move_uploaded_file to put the file in your
>> "incoming uploads" directory. At this point, you can also rename it to
>> whatever you want to call it. You might or might not choose to use some
>> or all of:
>>
>> uploading system ip
>> date and time
>> original filename
>>
>> to create a unique name, after all you can't have two files of the same
>> name in your temp dir. Or you could just number incoming files
>> sequentially starting at 1. What I'd probably do is make a note of the
>> original name, uploaders ip, time and date, create an md5 hash from it
>> and use that as the unique filename, and record the original information
>> in a log file.
>>
>> However, as you want to send an email, you could stick that information
>> in the message body, together with the unique filename that you gave it
>> in your incoming uploads directory
>>
>> So once you have the file in your incoming uploads directory, with
>> whatever filename you choose to give it derived however you decided to
>> derive it, you can now, by using a slightly modified version of the email
>> example that you have already been provided with, email it to yourself.
>>
>> We're not expecting you to become an expert, but please, to make the php
>> code to do what you want it to, you have to meet it half way and be
>> prepared to string a few functions and control statements together.
>>
>> If you're not capable of editing an example of code that uses a hardcoded
>> filename to use a variable one instead, then maybe you need to spend some
>> more time getting to grips with the basics of programming concepts and
>> editing files, and then the variable naming syntaxes etc of php, before
>> you start working on anything as ambitious as form handling, uploaded
>> files and sending emails.
>>
>> Rgds
>>
>> Denis McMahon
> OK. I have some code from the existing form handler page which I copied
> and removed everything about sending the email. I added some code for
> various things, then tried to test it. Instead of executing the code I
> got a redirect to the handler page which was blank.
>
> I am not going to put all the code here to save space, just what I
> added or changed since that is what killed it. Oh, yes, I am doing this
> on my localhost, and the original handler worked OK.
>
> First there is the validation stuff which checks to see if required
> fields are filled in and the image is the correct type. Then the form
> entries are placed into variables. Am I right in thinking the $_SERVER
> stuff is about uploading the image? This is in the original, but I
> included it to ask the question and to show where the variables used
> later came from. The original was created with Forms to Go, hence the
> $FTG in the variable names.
>
> if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
> $clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
> } else {
> $clientIP = $_SERVER['REMOTE_ADDR'];
> }
>
> $FTGheadshot = $_FILES['headshot']['name'];
> $FTGfirstname = DoStripSlashes( $_POST['firstname'] );
> $FTGlastname = DoStripSlashes( $_POST['lastname'] );
> $FTGaddress = DoStripSlashes( $_POST['address'] );
> $FTGcity = DoStripSlashes( $_POST['city'] );
> $FTGstate = DoStripSlashes( $_POST['state'] );
> $FTGzip = DoStripSlashes( $_POST['zip'] );
> $FTGhomenum = DoStripSlashes( $_POST['homenum'] );
> $FTGmaincontact = DoStripSlashes( $_POST['maincontact'] );
> $FTGcellnum = DoStripSlashes( $_POST['cellnum'] );
> $FTGworknum = DoStripSlashes( $_POST['worknum'] );
> $FTGfaxnum = DoStripSlashes( $_POST['faxnum'] );
> $FTGemail = DoStripSlashes( $_POST['email'] );
>
> After that I added code that is supposed to save the image to the
> directory "profiles/".
>
> # Save image to profiles directory
> $path = "profiles/";
> $path = $path . basename($FTGheadshot);
> if(move_uploaded_file($_FILES['headshot']['tmp_name'], $path)) {
> echo "The file ". basename( $_FILES['headshot']['name']).
> " has been uploaded";//moves file and notifies if successful
> } else{
> echo "There was an error uploading the file, please try
> again!";//or not
> }
>
> This before the validation failure redirect. Should it have been after
> that? Should I have the echo if there is no place to display it?
>
> Then comes the validation success line followed by"
>
> $new_profile = $FTGfirstname"_"$FTGlastname".html";
> $fh = fopen(profiles/$new_profile, 'w') or die("can't open file");
>
> This should create a new profile html page named
> firstname_lastname.html. Did I do that correctly? That is followed with
> some fwrite commands to write the html to the file:
>
> fwrite($fh, "<html>\n
> <head>\n
> <title>"$new_profile"</title>\n
> </head>\n
> <body>\n");
> fwrite($fh, "<table width=\"800\" border=\"1\" cellspacing=\"2\"
> cellpadding=\"10\"><tr>\n");
> fwrite($fh, "<td>firstname : $FTGfirstname<br />\n
> lastname : $FTGlastname<br />\n
> address : $FTGaddress<br />\n
> city : $FTGcity<br />\n
> state : $FTGstate<br />\n
> zip : $FTGzip<br />\n
> homenum : $FTGhomenum<br />\n
> maincontact : $FTGmaincontact<br />\n
> cellnum : $FTGcellnum<br />\n
> worknum : $FTGworknum<br />\n
> faxnum : $FTGfaxnum<br />\n
> email : $FTGemail<br /></td>\n");
>
> There is also this line: (inside an fwrite function)
>
> <img
> src=\"imgresize.php?w=400&amp;h=500&amp;constrain=1&amp;img=$path\ " />
>
> which is supposed to resize the image to fit the cell using code on an
> external page. I know the $path is wrong because it would contain the
> name of the image by this point. Should it just be the $FTGheadshot or
> $_FILES["headshot"]? Will this work if I don't have sessions enabled? I
> just thought of that though nothing was said about it on the site where
> I found the code.
>
> After that is the fclose($new_profile). Actually I just noticed I had
> put fclose($fh). Then comes:
>
> header("Location: success.php");
>
> followed by the closing } and ?>
>
> Is this enough for someone to see what I did wrong, or do I need to
> post the entire page? Or is it just so wrong I need to start over?

Do you have your code working without any PHP involved? That is, have
you gotten it to work if it's just plain text sent in the email?

As I've told you time and time again - but you refuse to listen. Until
you get your email text working like you want, you're just spinning your
wheels with PHP.

If you would have taken my advice on the 21st when I first sent it,
you'd have this working by now.

As it is, you're no further along than you were when you first asked -
because you're chasing the wrong problem. And if you don't start fixing
the RIGHT problem, you'll still be doing this in another month.

But I know. Some people are just too stoopid to learn. Maybe you need
to explore another line of work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: ip address of client
Next Topic: Islandnet.com dropping support for PHP4
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 15:24:07 GMT 2024

Total time taken to generate the page: 0.05241 seconds