PHP Scripting Problems ( EASY TO ANSWER )

Discussion in 'Mac Programming' started by JelvisChan, Mar 5, 2009.

  1. macrumors member

    Jan 9, 2009
    There are 2 things that I need help with using PHP:

    When someone submits a feedback form on my site, I want to email to go to my email address, of course!

    I have gotten that part done I think, but I have 2 problems on the scripting part of the php script:

    1.) Here is the part of the script I have a problem with:

    mail( "",
    $message, $topic, $email );
    --It is fine, but instead of just saying the message on the email, I want it so that it says what it is before it. For example:

    Message: Hello Jelvis!
    Topic: Cats

    After submitting, the form comes to my email, and it says:

    Hello Jelvis!

    Instead of saying that when it is sent, I want it so that it says this:

    (bold if possible) Message: Hello Jelvis!
    (bold if possible) Topic: Cats
    (bold if possible) Contact:

    Is there a way to do this using the script I provided above?


    2.) After the feedback form is submitted, the information goes to my email fine, but after I get the first message, about 15 minutes later I get 22 more of the same message, and then another 2 and it stops.

    Is there a way so that only 1 is sent?

    I pressed submit once when testing the php form, and then all of a sudden I get 25 emails of the same message, and if I get 5 people sending me a message using that form, that means I get 100 messages of 4 different kinds.

    I'm wondering if someone could give me an explanation and a solution to this.

    I really hope you guys can help me out!

  2. Moderator emeritus


    Aug 16, 2005
    For #1, just concatenate whatever else you want onto the $message.

    $message .= "\nSome extra info";
    For #2 we'd need to see your script in order to figure out why it's sending multiple times. You may have a loop that actually sends the messages that many times.
  3. macrumors member


    Oct 9, 2008
    Here's the PHP script I wrote. It's probably not perfect, and it's very simple as I'm fairly new to the language, but it might help with Question 1. Especially the $body section

    	$to = "Email"; // Enter your email here
    	$subject = "Subject"; // Enter a subject for all emails
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$message = $_POST['message'];
    	$body = "From: $name\nE-Mail: $email\n\nMessage:\n$message";
    if (isset($_POST['submit'])) {
    	$page = "Succes Page URL";
    	header("Refresh: 0; URL=\"" . $page . "\"");
    	mail($to, $subject, $body);
    } else {
    	$page = "Error Page URL";
    	header("Refresh: 0; URL=\"" . $page . "\"");
    This will result in one email sent to me containing,

    From: Name
    Email: Email

  4. 4np
    macrumors 6502a


    Feb 23, 2005
    The Netherlands
    #1 --> you can only format the email by using HTML e-mails. The native PHP mail function is text only, so you need to get a HTML / MIME mail class to do the job for you. You could, for example, look here or have a look at the Zend Framework. If that's too hard, stick with text only mails.

    #2 --> sounds like you pressed submit multiple times, your mail function is in a for or while loop, or the mailserver sending the email is buggy. To pinpoint the exact issue isn't possible with the information you specified...

    good luck :)

    ps. if you don't want to get spammed for life, remove the email address in your post...
  5. thread starter macrumors member

    Jan 9, 2009
    Thank you AngelWatt and Blindfutur3--

    I will try Blindfutur3's script, and if it works, then thank you very much, and if it doesn, I'll post my script up here for you all to analyze.

    Stay tuned, and thanks a bunch!
  6. macrumors member


    Oct 9, 2008
    You obviously might need to tailor my script to suit the fields you have in your form, but that should be easy enough. I'd also recommend using the script as a base to build off of, as it's very basic and could do with a whole lot of improving.

    The script should work, you can see it in action here*

    If you have any trouble, let me know.

    * If posting that link violates any TOS, please let me know and I'll remove it

    - John
  7. thread starter macrumors member

    Jan 9, 2009
    It should be fine, just stay tuned. I have one more question to ask, but Ill ask it after I finish this up.
  8. thread starter macrumors member

    Jan 9, 2009
    Here is my last problem for now:

    So far, there are no major problems with the php script or the mail process - knock on wood -

    But, there is a problem with the access of the html form.

    you see, i have port 80 enabled, and everything works ok.

    But, when I put my computer to sleep manually or automatically, every php script on my site shuts off, so when you submit the form, everything is confused and nothing loads.

    However, when my computer is active, the form works like a charm.

    Is there a way to make it so that whenever my computer is put to sleep, the php form still stands and remains active?

    I am open to parts of a script to add, or maybe if there is a site I need to visit.

    Thank you!
  9. macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    No, because your computer is asleep a.k.a hibernation mode.
  10. thread starter macrumors member

    Jan 9, 2009
    Then how do I get it so that my PHP/HTML scripts are always activated?
  11. Moderator emeritus


    Aug 16, 2005
    Configure your Mac not to sleep :)

    System Preferences > Energy Saver > Set slide to Never for computer sleeping.
  12. thread starter macrumors member

    Jan 9, 2009
    Does anyone know a php script where you can log in and access certain stuff?

    If you do, it would help if you told me.

Share This Page