Page 1 of 1
Why doesn't this work???
Posted: Sat Jun 26, 2004 5:56 pm
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!
Posted: Sat Jun 26, 2004 6:19 pm
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?
Posted: Sat Jun 26, 2004 6:35 pm
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...?
Posted: Sat Jun 26, 2004 7:41 pm
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
Posted: Sat Jun 26, 2004 8:11 pm
by John Cartwright
you should always include a reply to address or a lot of filters will not pass the email.. for example hotmail
Posted: Sat Jun 26, 2004 10:27 pm
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.
Posted: Sat Jun 26, 2004 10:51 pm
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.
Posted: Sat Jun 26, 2004 11:06 pm
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.
Posted: Sun Jun 27, 2004 9:26 am
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]