简体   繁体   中英

html form to edit php code

I'm working on a project that allows users to edit PHP code in PHP file.

I have a PHP page that uses the mail function to send emails. I want to allow the user to change the message sent out (in the mail function).

I know how to re-write over a file but how to edit it, I'm not sure...

So here's the mail function:

$name=$_POST['userName'];

$emaily=$_POST['userEmail'];

$email = "$sponsor_email"; 


$subject = "the subject"; 


$message = "This is the message I want the user to be able to edit."; 

mail($email, $subject, $message, "From: $user-email"); 

Now I've got the $message var printed out on in the html form (so the users can see what will be changed but i don't know how I'd go about actually writing the code to change it on from submit.

Any ideas?

Thanks!

Sorry guys....

I didnt explain the situation properly.

The php file with the mail function will not be used to send an email from that form. All i want the form to do is edit the php file basically. I don't want to send the email with this form, this is for users to edit the mail function. Hope thats more clear...

将文本区域放入名为“ message”的形式,然后执行$ message = $ _POST ['message'];。

create a PHP that read what is in the PHP file that contains code to be edited then print it out in a HTML textarea then make another file that will write that modified code in the PHP file that has the code(to be modified). You can use google find how to read and write in a file.

On your editing page, just do something like below:

$message = file_get_contents("path to message file");
echo "<textarea id=\"message\">".$message."</textarea>";

Then you can edit whatever the contents of the file were.

Might be better though if you used a database, and sanitized the user input - rather than saving everything to a file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM