php mail() code help

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
http://x10hosting.com/forums/free-hosting/112944-php-mail-stopped-working.html

DeadBattery who has been helping me suggested that I post my code for sending emails up here in case there is something wrong with it. The code used to work fine, but mid Janurary it stopped working. Thanks for taking a look guys.

PHP:
<?php if(isset($_POST['submit'])) {
$to = "*********@worthingtonbaptistchurch.com";
$selected = $_POST['Email:'];
$subject = "Worthington Baptist Church Contact Form -- To: $selected";
$messagesubject = $_POST['messagesubject'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "To: $selected\n From: $name_field\n E-Mail: $email_field\n Subject: $messagesubject\n Message: $message";
echo "Your letter has been sent to the appropriate person. Thank You.";
mail($to, $subject, $body);
} else {
echo "Access denied.";
}
?>
 
Last edited:

kbjradmin

New Member
Messages
512
Reaction score
2
Points
0
have you fixed this or do you still need help? you may want to try a different method all together. PHPMailer is pretty good.
 

farscapeone

Community Advocate
Community Support
Messages
1,165
Reaction score
27
Points
48
First of all you have a big security problem with the script you are using. You geting $_POST data and pass it directly to your mail function. This is where hacker and come in. You have to use stripslashes() function to make sure all that "nasty" scripts won't come through.

If it worked before then I guess there's nothing wrong with it. It may be that your script stopped working because mail server is down cos of all the updates going on now. It could also be that your PHP setting are not right.
 

drf1229

New Member
Messages
71
Reaction score
1
Points
0
I've had problems with mail, as some messages don't go through. I've avoided this by using google's smtp server instead.
 

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
Thanks for the reply I have been hopeing someone would help me. No, it still is not working.

So to make the code hacker safe would I do this to all the varibles I pull from the $_POST?
PHP:
$selected =  stripslashes($_POST['Email:']);

PHPMailer does sound nice the way it can use a gmail account to send the mail I'll have to give it a try. Thanks for the help.
 

wbaptist

New Member
Prime Account
Messages
24
Reaction score
1
Points
3
I just tested PHPMailer using gmail and it works!!! Now all I need to find out is if the PHP code I posted above will keep hackers out?
 
Last edited:
Top