Results 1 to 10 of 10
  1. #1

    Default Update a web page via e-mail?

    Here is what I want to do. I'm sure it's possible but unsure how to write the script.
    I'm pretty sure WH4 email can be set up to redirect to a script.

    A user sends an email to a "news" account.
    That account sends the email to a php script that extracts the body text (removing any html and images) and saves the text to a file named "news.txt".
    The index.php page reads the news.txt file and adds it's content to the web page.

    Any code wizards out there know how to do this with email, or know of some existing code?
    You can discover more about a person in an hour of play than in a year of conversation.
    -Plato.

  2. #2
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    Hmm... yes what you want to do is possible. I think this article should get you started in the right direction. http://www.evolt.org/incoming_mail_and_php I think the WH4 (cPanel) has everything you need to do this and PHP is compiled as a CGI binary. The stuff in Step one Email to PHP is kind of relevant but you'll be using cPanel to set this up and not editing any files. Not sure of the particulars on that but it is pretty straight forward when you get in there if I recall.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  3. #3

    Default

    Thanks wildjoker!
    That's a lot simpler than I thought it would be.
    You can discover more about a person in an hour of play than in a year of conversation.
    -Plato.

  4. #4
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    Your welcome. Let me know if you run into any road bumps with this.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  5. #5

    Default

    I have an email set up to send to and I have cPanel set up to pipe email arriving for that account to my php program.
    But when I send the email it keeps failing and gets bounced back, and the program is not run.
    The error says-
    A message that you sent could not be delivered to one or more of its
    recipients. This is a permanent error. The following address(es) failed:
    pipe to |/home1/mysite/public_html/LCC/myprogram.php
    It has the full path to my program that is to process the mail. I have the permissions wide open.
    Any idea what I am doing wrong? Is the server not finding the program?
    Here is the php code of what is supposed to get the email-
    Code:
    <?php
    // read from stdin
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
        $email .= fread($fd, 1024);
    }
    fclose($fd);
    
    $outFile = fopen("sign.txt","w");
    fwrite($outFile,$email);
    fclose($outFile);
    
    return null;
    ?>
    Last edited by Armadillo; 11-18-2011 at 01:29 AM.
    You can discover more about a person in an hour of play than in a year of conversation.
    -Plato.

  6. #6
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    It may be the email pipe you set up in cPanel. It should look like this:
    Code:
    | php -q /home1/mysite/public_html/LCC/myprogram.php

    If that does not help try putting this as your first line in myprogram.php.
    PHP Code:
    #!/usr/bin/php -q 
    myprogram.php file should be chmod to 755.

    The -q in both of the above should keep a bounce back email from being sent. You might also want to remove the closing tag ?> and the return null; Got that from here: http://kb.siteground.com/article/How...HP_script.html Again these things keep any output being returned to sendmail so that you don't get bounce back emails.

    If all the above does not make any difference then see if there is an error php file in /home1/mysite/public_html/LCC/ that might have information on why the php file itself is not working.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  7. #7

    Default

    Edit-
    I had a long post written up because nothing worked. Now it does work. Not sure why.
    I added the "hashbang" and removed the end tags, but it still failed.
    I changed "home1" to "home" in the path (both work in FTP). Didnt seem to make any difference.
    I was using "w+" instead of "w" where it outputs the file. Changed it back to "w".
    Now it works! Dont know why, but it's working.

    Thanks again Shawn!
    Last edited by Armadillo; 11-18-2011 at 10:50 PM.
    You can discover more about a person in an hour of play than in a year of conversation.
    -Plato.

  8. #8
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    Glad it is working for you!
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  9. #9

    Default

    Found something odd.
    If I put the new website folder in the site root folder (/home/mysite/newsite) it bounces mail with an error about not recognizing the -q on the hashbang.
    But if I put the website in the same folder as my main site (/home/mysite/public_html) everything works fine.

    I guess it dosnt make any difference where the files are located. Just seems like it would be more secure if I separated them.
    Any reason you know of why it would work in one location but not the other?
    Last edited by Armadillo; 11-24-2011 at 07:25 PM.
    You can discover more about a person in an hour of play than in a year of conversation.
    -Plato.

  10. #10
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    If you have the email pipe set up correctly in cPanel with the call to php -q then you shouldn't need the shebang line in your script. Also the -q simply turns off email notification in case of an error so you don't have to have it.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •