Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JelvisChan

macrumors member
Original poster
Jan 9, 2009
77
0
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

Moderator emeritus
Aug 16, 2005
7,852
9
USA
For #1, just concatenate whatever else you want onto the $message.

PHP:
$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

macrumors member
Oct 9, 2008
74
0
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

Code:
<?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

macrumors 6502a
Feb 23, 2005
972
2
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...
 

JelvisChan

macrumors member
Original poster
Jan 9, 2009
77
0
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

macrumors member
Oct 9, 2008
74
0
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
 

JelvisChan

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

JelvisChan

macrumors member
Original poster
Jan 9, 2009
77
0
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!
 

JelvisChan

macrumors member
Original poster
Jan 9, 2009
77
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.