Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accept string mail and send to the user (php)

Status
Not open for further replies.

Papik

MIS
Aug 10, 2001
17
0
0
AR
Hi people!, please if someone can help...

Need a .php that request a name and an email from a user and then call an external shell script that replace in a text file a generic name with the name entered from the user, compress it and send to the email entered from the user.
I dont have so much experience with PHP but it seems to me that shouldnt be something difficult to do it.
Can someone help me with a .php example or something?
Thanks in Advance
Papik
 
Code:
<?php
if (isset($_POST['name'])):
mail($_POST['email'], 'Subject',sprintf(file_get_contents('template.txt'),$_POST['name']));
endif;
?>

note that you should check the email field to make sure it is not a form attack
 
Thanks Jpadie, but as far as i can see this solve the mail sending issue but i need:

php code to:

1-accept 2 box text from the user (name, email)
2-call a linux shell script with these 2 parameters ( let's name it /home/test/script.sh para1 para2) that would replace a generic name with the name entered from the user
3-take the result for the script (template.txt replaced correctly) and send it to the user.
I know there must be a way to do it simple and effective but i cant figure out...
Thanks Again!
Papik
 
Hi

Papik said:
2-call a linux shell script with these 2 parameters ( let's name it /home/test/script.sh para1 para2) that would replace a generic name with the name entered from the user
PHP is very skilled in text processing. Why should an external script be involved ?

Feherke.
 
because i dont know how to do it in php and i know how to do it with sed for example in an external shell script.
The goal is very simple, replace several string in a file.txt with the user entered strings( i.e is a letter and i need to personalize it for each user)...
also gzip it and send it to the user...
can all these steps be done in php?
feel free to suggest pls
Thanks!
 
Hi

Papik said:
i know how to do it with sed for example
[tt]sed[/tt] uses regular expressions. PHP can also use regular expressions. ( See [tt]preg_replace()[/tt]. ) But there is absolutely no need for regular expressions, as you probably want to replace a fixed string. ( See [tt]str_replace()[/tt], [tt]strtr()[/tt]. )

And yes, zipping can also be done in PHP, however is abit more complicated. ( But I see no reason to do it. )

Feherke.
 
thanks feherke, gonna check that functions.
Can someone give an example of doing all this steps that i post before with php?
Thanks!
 
the code I posted will
+ take used input in two html fields: email and name
+ ingest a template: template.txt
+ replace a placeholder in the form %s within the template with the value of the name text field
+ mail the resultant merged template to the address specified in the email text field.
 
all this with just one line??
well incredible!,
the only requirement that is missing is that the file must be winzipeed before we can send it to the user..
Thanks!!!
 
then the easiest solution is to use phpmailer. you can hard code attachments in the message body, but it's a pain.

to zip, use php's zip function

Code:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
$zip->addFromString('template.txt', sprintf(file_get_contents('template.txt'),$_POST['name']));
$zip->close();
?>
 
thanks jpadie and feherke,
for all your valuable inputs !
Regards,
Papik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top