PDA

View Full Version : PHP Scripting Problems ( EASY TO ANSWER )




JelvisChan
Mar 5, 2009, 01:23 PM
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( "porsche105@mac.com",
$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
Email: email@email.com
SUBMIT

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

Hello Jelvis!
Cats
email@email.com

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: email@email.com

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!

Thanks,
Jelvis



angelwatt
Mar 5, 2009, 03:33 PM
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.

Blindfutur3
Mar 5, 2009, 04:03 PM
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


<?php

$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

Message:
Message

4np
Mar 5, 2009, 04:10 PM
#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 (http://www.phpguru.org/static/mime.mail.html) or have a look at the Zend Framework (http://www.zftutorials.com/zend-mail-zend-mime/). 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...

JelvisChan
Mar 5, 2009, 11:36 PM
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!

Blindfutur3
Mar 6, 2009, 01:42 AM
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 (http://tinyurl.com/dc4yzz)*

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

JelvisChan
Mar 6, 2009, 10:00 AM
It should be fine, just stay tuned. I have one more question to ask, but Ill ask it after I finish this up.

JelvisChan
Mar 6, 2009, 11:06 AM
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!

Cromulent
Mar 6, 2009, 11:12 AM
Is there a way to make it so that whenever my computer is put to sleep, the php form still stands and remains active?

No, because your computer is asleep a.k.a hibernation mode.

JelvisChan
Mar 6, 2009, 12:31 PM
Then how do I get it so that my PHP/HTML scripts are always activated?

angelwatt
Mar 6, 2009, 01:19 PM
Then how do I get it so that my PHP/HTML scripts are always activated?

Configure your Mac not to sleep :)

System Preferences > Energy Saver > Set slide to Never for computer sleeping.

JelvisChan
Mar 8, 2009, 12:43 AM
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.