1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need a simple php code created

Discussion in 'PHP & Perl' started by webdy, Feb 10, 2013.

  1. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    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 $
     
  2. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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
     
  3. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    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/files/45354600/E%20Commerce%20Email%20Template_Theme%20Preview/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.
     
  4. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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..
     
  5. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    Thank you very much.
     
  6. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
  7. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:

    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?
     
  8. metra

    metra Junior Member

    Joined:
    Jun 6, 2012
    Messages:
    156
    Likes Received:
    49
    Location:
    -. ..- .-.. .-..
    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
     
  9. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
  10. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:

    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.
     
  11. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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..
     
  12. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    I`m testing it directly on hostgator vps.
    Config file holds the recipients email it just does not send the email.html to $email3
     
  13. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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..
     
    • Thanks Thanks x 1
  14. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    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?
     
  15. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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..
     
  16. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    I`m getting an empty email with
    "hello".
     
  17. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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..
     
  18. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    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 "";?>
     
  19. webdy

    webdy Registered Member

    Joined:
    Jan 20, 2012
    Messages:
    67
    Likes Received:
    21
    Home Page:
    i tried to put one statement a line but it doesn`t show like that,
     
  20. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,261
    Likes Received:
    1,794
    Location:
    www.Indexification.com
    Home Page:
    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..
     
    • Thanks Thanks x 1