Why doesn't this work???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gerb
Forum Newbie
Posts: 3
Joined: Sat Jun 26, 2004 5:56 pm

Why doesn't this work???

Post by Gerb »

Register_globals OFF has messed me up no end - now my mail script doesn't work:

<?
$to="myemail@mydomain.co.uk";

mail( "myemail@mydomain.co.uk", "Feedback from my domain", $_POST['Name'],$_POST['Company'], $_POST['Email'], $_POST['Comment'], "From: {$_POST['Email']}" );

?>

What's wrong here???

Thanks!
crabyars
Forum Commoner
Posts: 37
Joined: Thu Jun 17, 2004 8:24 pm

Post by crabyars »

well for starters I don't see your $to variable being passed after it has been declared.

are there any error messages being thrown?
Gerb
Forum Newbie
Posts: 3
Joined: Sat Jun 26, 2004 5:56 pm

Post by Gerb »

Sorry, to be honest I'm not familiar with PHP. I used a script from the web to handle my form, but now need to deal with setting it up for a register_global off server.

It works fine when I remove the following code:

$_POST['Company'], $_POST['Email'], $_POST['Comment'],

If I add it back in (which is just passing more variables to the email surely?) it doesn't work - nothing gets sent to my email.

Odd...?
crabyars
Forum Commoner
Posts: 37
Joined: Thu Jun 17, 2004 8:24 pm

Post by crabyars »

I have a minimal example on my php snippets site here is the code:

Code: Select all

<?php 

mail("root@localhost.com", "This is the SUBJECT", "This is the BODY"); 

?>
If you want more info, maybe check the php documentation
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you should always include a reply to address or a lot of filters will not pass the email.. for example hotmail
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

<?
$to = "myemail@mydomain.co.uk";
$content = $_POST['Name'] . $_POST['Company'] . $_POST['Email'] . $_POST['Comment']; 
mail($to,"Feedback from my domain",$content,"From: {$_POST['Email']}");
?>
Try that. However the email will come out without formatting (all on one line, no spacing, etc..) until you add it to the $content line.
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

Post by snpo123 »

Gerb wrote:Sorry, to be honest I'm not familiar with PHP. I used a script from the web to handle my form, but now need to deal with setting it up for a register_global off server.

It works fine when I remove the following code:

$_POST['Company'], $_POST['Email'], $_POST['Comment'],

If I add it back in (which is just passing more variables to the email surely?) it doesn't work - nothing gets sent to my email.

Odd...?
I have the same problem sometimes. Just covert the POST variables into usable ones, like so:

Code: Select all

$company = $_POST['Company'];
$email = $_POST['Email'];
$comment =  $_POST['Comment'];
Then just put the new variables into the mail function. It should work.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

No, it won't. He's passing multiple parameters, not variables. If you want to add them all to the content of the email, put them into a variable before hand, or just put them straight into the function, with a period to connect them, not a comma.
Gerb
Forum Newbie
Posts: 3
Joined: Sat Jun 26, 2004 5:56 pm

Post by Gerb »

Thanks people,

LiLpunkSkateR's code did the trick, but I've edited it to format the email correctly, as shown below.

Hopefully this will help someone else...

Code: Select all

<? 
$to = "email@mydomain.co.uk"; 
$content = "Name: " . $_POST['Name'] . "\n\n" . "Company: " . $_POST['Company'] . "\n\n" . "Email: " . $_POST['Email'] . "\n\n" . "Comment: " . $_POST['Comment']; 
mail($to,"Feedback from mwww.mydomain.co.uk",$content,"From: {$_POST['Email']}"); 
?>

Thanks again...


feyd | gerb, please start using the

Code: Select all

tags we have provided :: [/color][url=http://forums.devnetwork.net/viewtopic.php?t=21171][color=red]:arrow: [u][b]Posting Code in the Forums[/b][/u][/color][/url]
Post Reply