Jump to content

editing strings in an existing file with a form


Recommended Posts

this is tricky to explain:


I have a raw php script, written by someone else, that sends an email to a list extracted from a CSV file. It requires that certain values in the file be manually edited each time it's used, such as the following:


$mail->setFrom('email@email.com', 'From Name'); // <==== change email address, From Name
$subject = "Subject Line"; // <==== Adjust this subject
$html = ' html here '; // <==== include email html
MagicParser_parse("test.csv","myRecordHandler","csv|44|1|34"); // <==== change 'test.csv' file name


the function is called by simply calling this email.php file in the browser.


I'd like to build a form that would a) edit these values/strings on the fly and then b) call the file in the browser. The thing is, it's been a while since I've messed with PHP forms to any extent, and I can't remember how to get started on something like this. And I'm not familiar at all with fopen and fwrite to edit strings like this without messing up the existing code (there's a lot of other code in the file that needs to be left alone, obviously).


I'm hoping someone can help me with a starting point - an idea on how to get this thing going - whether to build the form right in the same file or to build one in another file that posts these values to this existing file...


hopefully someone can understand what I'm asking, and thank you much for your help.




Link to comment
Share on other sites

First off: The script is protected with a password or an equivalent mechanism, right? Because if anybody can send out e-mails simply by visiting the URL, that's obviously a problem.


As to your question: You don't fwrite() to the script at all. This is insecure, cumbersome, error-prone and entirely unnecessary. What you do instead is use dynamic e-mail addresses and filenames. So you replace the current hard-coded strings with references like $_POST['email_address'] and $_POST['csv_path']. The script will then use whatever value has been submitted through the form instead of relying on predefined values.


The form can and should be in the same file. If you don't fully understand how this works, I suggest you start with a small test script which merely echoes the form input. When this works, you can extend the script and integrate your current code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.