Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-26-2012, 05:22 PM   PM User | #1
jack0987
New to the CF scene

 
Join Date: Nov 2012
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
jack0987 is an unknown quantity at this point
form mailer code help

Please help with this php code. C and C# are really my languages.

It is intended to take the fields in a web form and place them in an email.

The other day, two emails were received only containing the line
"Below is the result of your feedback form. It was submitted on $date at $time.\n\n"
with no field information.

Might there be a flaw in this code?


<?PHP

// Change "me@this.com" to your email. (you must keep the "" marks)
$to = "me@this.com";

// This will be the subject of the Email when it is sent.
$subject = "Results from your Request Info form";

// This will be who it is from, usually My site or something like that
$headers = "From: My Site";


// redirect? 1=yes 0=no (this is the page you go to after you submit the form.
// if left on 0 you will see a message then nothing will happen
// if you select 1 you will see a message then go to the redirect page.)
$forward = 0;


// This will be the page you are redirected.
// (if you keep it 0 you do not need one just delete "yoursite.com"; and leave ""; instead)
$location = "yoursite.com";


$date = date ("l, F jS, Y");
$time = date ("h:i A");

$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n";

if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}

?>
jack0987 is offline   Reply With Quote
Old 11-27-2012, 12:26 AM   PM User | #2
Thyrosis
New Coder

 
Join Date: Nov 2012
Posts: 72
Thanks: 4
Thanked 11 Times in 11 Posts
Thyrosis is on a distinguished road
There shouldn't be anything wrong with the code as far as I can spot, the empty message you received can only have been from an empty form. Are you catching that on the front end at all?

Apart from that, if you experience problems related to receiving filled in forms, try the following:

a) start with commenting out everything from mail() downwards.
b) echo $msg, see what that looks like. If it shows all of your filled in data, it's all good. If not, continue.
c) print_r[$_SERVER['POST']; OR print_r[$_SERVER['GET']; - see below
--> out of curiousity: why check for POST and GET? Surely you define your form at front end as either POST or GET, not randomly or anything? Pick either one and use that as print_r to see what gets through

If that doesn't lead you anywhere, get back with the results of that and possibly the form too. Good luck!

Regards,
Martin
Thyrosis is offline   Reply With Quote
Users who have thanked Thyrosis for this post:
jack0987 (11-27-2012)
Old 11-27-2012, 08:21 AM   PM User | #3
jack0987
New to the CF scene

 
Join Date: Nov 2012
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
jack0987 is an unknown quantity at this point
Thanks Martin for a very considered response.

The php code was not done by me. It is on a friends web site and I was helping him.

On the front end only post is being used. Could we safely remove the else part?

Prehaps another php mailer may help. Could you suggest one?
jack0987 is offline   Reply With Quote
Old 11-27-2012, 08:42 AM   PM User | #4
ramsingh
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 2
Thanked 1 Time in 1 Post
ramsingh is an unknown quantity at this point
how to solve the parse error in php

following is my php code and the error reads like this parse error in .../mainthead php at line 4 - unexpected T_STRING, expecting ',' or ';'

<?php
session_start();
echo "<!--- Main Head Starts --->;
\n<link href="assets/jodohStyles.css" rel="stylesheet" type="text/css" /> \n " ;
\n<link rel="stylesheet" href="assets/style.css"/>
\n";
echo "<s";
echo "tyle type="text/css">
\n -->
\n</style>;
\n
<div id="page">
<span id="e1"></span>
</div>
\n <d";
\n " ;
$row
$_SESSION
$_SESSION
?>
ramsingh is offline   Reply With Quote
Users who have thanked ramsingh for this post:
jack0987 (11-27-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:04 PM.


Advertisement
Log in to turn off these ads.