tags:

views:

140

answers:

5

Ok, so I made a form using HTML, and I'd like to get it to submit the information to my email, so I found and modified this PHP script:

<?php
$to = "[email protected]";
$subject = "R&R Form";
$firstname1 = $_REQUEST['firstname1'] ;
$lastname1 = $_REQUEST['lastname1'] ;
$firstname2 = $_REQUEST['firstname2'] ;
$lastname2 = $_REQUEST['lastname2'] ;
$department1 = $_REQUEST['department1'] ;
$department2 = $_REQUEST['department2'] ;
$reason = $_REQUEST['reason'] ;
$behaviour1 = $_REQUEST['behaviour1'] ;
$behaviour2 = $_REQUEST['behaviour2'] ;
$behaviour3 = $_REQUEST['behaviour3'] ;
$behaviour4 = $_REQUEST['behaviour4'] ;
$behaviour5 = $_REQUEST['behaviour5'] ;
$behaviour6 = $_REQUEST['behaviour6'] ;
$behaviour7 = $_REQUEST['behaviour7'] ;

$message = "Nominee: $firstname1 $lastname1 /n Department: $department1 /n /n Nominator: $firstname2 $lastname2 /n Department: $department2 /n /n Reason for nomination: $reason /n /n Additional reasons: $behaviour1 /n $behaviour2 /n $behaviour3 /n $behaviour4 /n $behaviour5 /n $behaviour6 /n $behaviour7 /n";

$headers = "Recognition and Reward Request for $firstname1 $lastname1";
$sent = mail($to, $subject, $message, $headers,) ;
if($sent)
{print "Your nomination was submitted successfully"; }
else
{print "We encountered an error submitting your nomination"; }
?>

It's not very well written, I know (I only started learning php today, and I just modified a script I copy and pasted.), but it doesn't seem to have any syntax errors or any other errors I can see. I'm not asking for someone to fix my code for me, I'm just asking for some pointers as to why the script isn't working as it should.

I uploaded it to a server with PHP installed, so that's not the problem. I've been trying to figure this out all day, and it's getting kinda frustrating. Someone please help?

+1  A: 

Since you are a starter I recommend you to use PEAR as much as possible.

Look at: pear html quickform

It will really make your life easier.

And for sending e-mails, I suggest you to use: PHPMailer

It comes with a lot of e-mail features just right out-of-the-box

Sander Pham
A: 

The first problem I see is that $headers doesn't contain valid headers. Headers are things like From: [email protected] or CC: [email protected], but you're treating it as part of the email.

Here's some info on email headers.

Brendan Long
+2  A: 

Well, the script is using this for the headers, which is invalid:

$headers = "Recognition and Reward Request for $firstname1 $lastname1";

Maybe you meant for that to be the subject line?

The headers should be valid SMTP headers, like this:

$headers = 'From: [email protected]' . "\r\n";

Look at the examples for the mail function for more info.

Eric Petroelje
+1 because i agree
DRL
+2  A: 
$sent = mail($to, $subject, $message, $headers,) ;

should look like this:

$sent = mail($to, $subject, $message, $headers) ;

(without the comma)

hope i helped

WEBProject
A: 

It does have syntax errors. Since you cannot see them, I suggest you enable full error reporting. There're many ways to do it; the simplest is probably adding this code on top of your script:

<?php

ini_set('display_errors', true);
error_reporting(E_ALL);

?>
Álvaro G. Vicario
Wow, thanks for all your responses!
Ismail