need a simple php code created

webdy

Registered Member
Joined
Jan 20, 2012
Messages
67
Reaction score
21
So I have a small generator that adds content to a config.php file but I also want to to send an email to the recipient.
Can you please help me.
Here is the generator code:
PHP:
<?php
if (isset($_POST["Submit"])) {
$string = '<?php $date1 = "'. $_POST["date1"]. '";$email2 = "'. $_POST["email2"]. '";$email1 = "'. $_POST["email1"]. '";?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);
}
?><style type="text/css"><!--.style1 {color: #000000}--></style>
<form action="" method="post" name="install" id="install">

And here si the config:
PHP:
<?php $date1 = "";$email2 = "";$email1 = "";?>
I need a command code when the generator.php is submitted it will also send a email.html with the $date1 details and so on.
Can anyone help? rep and thanks given even a quick $
 
Code:
[COLOR=#000000][COLOR=#0000BB]<?php
[/COLOR][COLOR=#007700]if (isset([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"Submit"[/COLOR][COLOR=#007700]])) {
[/COLOR][COLOR=#0000BB]$string [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]'<?php $date1 = "'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"date1"[/COLOR][COLOR=#007700]]. [/COLOR][COLOR=#DD0000]'";$email2 = "'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"email2"[/COLOR][COLOR=#007700]]. [/COLOR][COLOR=#DD0000]'";$email1 = "'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"email1"[/COLOR][COLOR=#007700]]. [/COLOR][COLOR=#DD0000]'";?>'[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000BB]$fp [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]fopen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"config.php"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"w"[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]fwrite[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$string[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]fclose[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700]);

$emailbody=[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]$date1[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700];
mail($email1,'Subject Here',$emailbody);
}
[/COLOR][COLOR=#0000BB]?>[/COLOR]<style type="text/css"><!--.style1 {color: #000000}--></style>
<form action="" method="post" name="install" id="install">[/COLOR]

Simply put whatever you need in $emailbody... also change $email1 with the proper variable holding the recipient address, and change your subject..

let me know if you need any more help..

also you can refer to: http://www.php.net/manual/en/function.mail.php
 
Code:
[COLOR=#000000][COLOR=#0000BB]<?php
[/COLOR][COLOR=#007700]if (isset([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"Submit"[/COLOR][COLOR=#007700]])) {
[/COLOR][COLOR=#0000BB]$string [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]'<?php $date1 = "'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"date1"[/COLOR][COLOR=#007700]]. [/COLOR][COLOR=#DD0000]'";$email2 = "'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"email2"[/COLOR][COLOR=#007700]]. [/COLOR][COLOR=#DD0000]'";$email1 = "'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"email1"[/COLOR][COLOR=#007700]]. [/COLOR][COLOR=#DD0000]'";?>'[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000BB]$fp [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]fopen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"config.php"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"w"[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]fwrite[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$string[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]fclose[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700]);

$emailbody=[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]$date1[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700];
mail($email1,'Subject Here',$emailbody);
}
[/COLOR][COLOR=#0000BB]?>[/COLOR]<style type="text/css"><!--.style1 {color: #000000}--></style>
<form action="" method="post" name="install" id="install">[/COLOR]

Simply put whatever you need in $emailbody... also change $email1 with the proper variable holding the recipient address, and change your subject..

let me know if you need any more help..

also you can refer to: http://www.php.net/manual/en/function.mail.php

Hi innozemec and thanks for your reply.
I`m a noob in php so for me is just copy and paste.
I`m planning to send as a confirmation when the form is submitted a newsletter like this picture here:
http://1.1.1.1/bmi/0.s3.envato.com/... Email Template_Theme Preview/04_preview4.jpg
It will be a full html and the generator will replace some values in the newsletter with the content of the form submitted and send it to the $date1.

Can you please show me an example of code that I can use to develop in a full working script.
 
your image doesn't load.. anyways here's a sample code...

Code:
$emailbody=file_get_contents('PATH_TO_HTML_FILE_HERE');

$emailbody=str_replace('VARIABLE',$date1,$emailbody);
$emailbody=str_replace('VARIABLE2',$email2,$emailbody);

mail($mail1,'subject here',$emailbody);

simply do the necessary changes of the code and add as many str_replaces as you need before mailing..
 
your image doesn't load.. anyways here's a sample code...

Code:
$emailbody=file_get_contents('PATH_TO_HTML_FILE_HERE');

$emailbody=str_replace('VARIABLE',$date1,$emailbody);
$emailbody=str_replace('VARIABLE2',$email2,$emailbody);

mail($mail1,'subject here',$emailbody);

simply do the necessary changes of the code and add as many str_replaces as you need before mailing..

Thank you very much.
 
no probs, keep me posted if you need any more help


PHP:
$method = "'. $_POST["method"]. '";?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);
$emailbody=file_get_contents('newsletter.html');
$emailbody=str_replace('VARIABLE',$var1,$emailbody);$emailbody=str_replace('VARIABLE2',$var2,$emailbody);$emailbody=str_replace('VARIABLE3',$va3,$emailbody);$emailbody=str_replace('VARIABLE4',$var4,$emailbody);
mail($email3,'You registration was a success',$emailbody);}
?>
But it does not send :(
Can you please tell me what am I doing wrong?
using phpdesigner 8 it shows a red line where $emailbody=file_get_contents('newsletter.html'); is .
Any suggestions?
 
PHP:
$method = "'. $_POST["method"]. '";?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);
$emailbody=file_get_contents('newsletter.html');
$emailbody=str_replace('VARIABLE',$var1,$emailbody);$emailbody=str_replace('VARIABLE2',$var2,$emailbody);$emailbody=str_replace('VARIABLE3',$va3,$emailbody);$emailbody=str_replace('VARIABLE4',$var4,$emailbody);
mail($email3,'You registration was a success',$emailbody);}
?>
But it does not send :(
Can you please tell me what am I doing wrong?
using phpdesigner 8 it shows a red line where $emailbody=file_get_contents('newsletter.html'); is .
Any suggestions?

There were a few syntax errors in the code:
PHP:
$method = $_POST["method"];
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);
$emailbody=file_get_contents('newsletter.html');$emailbody=str_replace('VARIABLE',$var1,$emailbody);$emailbody=str_replace('VARIABLE2',$var2,$emailbody);$emailbody=str_replace('VARIABLE3',$va3,$emailbody);$emailbody=str_replace('VARIABLE4',$var4,$emailbody);
mail($email3,'You registration was a success',$emailbody);

Try to see if that works. I haven't tested this so not sure - assuming your initial code was correct, the above version is the exact same with syntax errors fixed :)

Best,
- Metra
 
there's an error at the end.. from where that extra } comes in..
 
there's an error at the end.. from where that extra } comes in..


PHP:
<?php
if (isset($_POST["Submit"])) {
$string = '<?php $var = "'. $_POST["var"]. '";$var2 = "'. $_POST["var2"]. '";$var3 = "'. $_POST["var3"]. '";$var4 = "'. $_POST["var4"]. '";$method = $_POST["method"];?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);$emailbody=file_get_contents('newsletter.html');$emailbody=str_replace('VARIABLE',$var,$emailbody);$emailbody=str_replace('VARIABLE2',$var2,$emailbody);$emailbody=str_replace('VARIABLE3',$var3,$emailbody);$emailbody=str_replace('VARIABLE4',$var4,$emailbody);
mail($email3,'You registration was a success',$emailbody); }
?>

Thats all the code tried it a lot of times and no success.
 
PHP:
<?php
if (isset($_POST["Submit"])) {
$string = '<?php $var = "'. $_POST["var"]. '";$var2 = "'. $_POST["var2"]. '";$var3 = "'. $_POST["var3"]. '";$var4 = "'. $_POST["var4"]. '";$method = $_POST["method"];?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);$emailbody=file_get_contents('newsletter.html');$emailbody=str_replace('VARIABLE',$var,$emailbody);$emailbody=str_replace('VARIABLE2',$var2,$emailbody);$emailbody=str_replace('VARIABLE3',$var3,$emailbody);$emailbody=str_replace('VARIABLE4',$var4,$emailbody);
mail($email3,'You registration was a success',$emailbody); }
?>

Thats all the code tried it a lot of times and no success.

ok, what exactly is not working?
Is it writing the config at all?
Is the $email3 variable holding the recipient's email?
Where are you testing the script? If on your local windows machine, then no email will be sent as local mail server is not configured by default..
 
I`m testing it directly on hostgator vps.
Config file holds the recipients email it just does not send the email.html to $email3
 
well, i see in the config you write variables like $_POST["var"]..., while in the mail() you put $email3
are you sure there is something in $email3 variable? echo its content to make sure there is content in it..

the same for str_replace()... in your config you use $_POST[..], while in the str_replace() you use direct variables.. if your register_globals is turned off, then all those variables will be empty..
 
register_globals is on
$var3= $email3
I replaced it. I don`t really get it why is not working.
Can you test it on your server? Can you do that?
 
there's no need to test it on my server as i am sure it should work.. i have done this thousands of times..

there might be some server issue.. try this

make a tmp.php file with just this content:

Code:
<?php
error_reporting(E_ALL);
mail('PUT_YOUR_EMAIL_HERE','Hello','Hello');
?>

upload the tmp.php to your server and visit its url in your browser.. see for any errors and check your email if you received an email..
 
there's no need to test it on my server as i am sure it should work.. i have done this thousands of times..

there might be some server issue.. try this

make a tmp.php file with just this content:

Code:
<?php
error_reporting(E_ALL);
mail('PUT_YOUR_EMAIL_HERE','Hello','Hello');
?>

upload the tmp.php to your server and visit its url in your browser.. see for any errors and check your email if you received an email..
I`m getting an empty email with
"hello".
 
ok, then mailing is good, there is some issue in your code..

now paste me the exact full code you use and make it one statement a line, as it is hard to be read here with multiple statements a line..
 
This is the form:
PHP:
<?php
if (isset($_POST["Submit"])) {
$string = '<?php $name = "'. $_POST["name"]. '";$title = "'. $_POST["title"]. '";$email3 = "'. $_POST["email3"]. '";$description = "'. $_POST["description"]. '";?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);
$emailbody=file_get_contents('newsletter.html');
$emailbody=str_replace('VARIABLE',$name,$emailbody);$emailbody=str_replace('VARIABLE2',$title,$emailbody);$emailbody=str_replace('VARIABLE3',$email3,$emailbody);$emailbody=str_replace('VARIABLE4',$description,$emailbody);
mail($email3,'Your registration was confirmed ',$emailbody);}
?>

And this is the config:

PHP:
<?php $name = "";$title = "";$descption = "";$email3 = "";?>
 
i tried to put one statement a line but it doesn`t show like that,
 
change to this code and execute:

Code:
 <?php
error_reporting(E_ALL);
if (isset($_POST["Submit"])) {
$string = '<?php $name = "'. $_POST["name"]. '";$title = "'. $_POST["title"]. '";$email3 = "'. $_POST["email3"]. '";$description = "'. $_POST["description"]. '";?>';
$fp = fopen("config.php", "w");fwrite($fp, $string);fclose($fp);
$emailbody=file_get_contents('newsletter.html');
$emailbody=str_replace('VARIABLE',$name,$emailbody);$emailbody=str_replace('VARIABLE2',$title,$emailbody);$emailbody=str_replace('VARIABLE3',$email3,$emailbody);$emailbody=str_replace('VARIABLE4',$description,$emailbody);
echo $_POST["email3"];
mail($_POST["email3"],'Your registration was confirmed ',$emailbody);}
?>

see if your get any email printed out and email sent to the recipient email..
 
Back
Top