Jump to content

PHP version problems? Global Variables?!


spikypunker

Recommended Posts

Hi people, first post on here.

 

Relatively new at PHP but have been using php for running mySql and also for a form emailer. I've used this simple script on a few sites:

 

<form action="mail.php" method="post">
    
    Name:  <input name="name" type="text" size="40" maxlength="30" /><br /><br />
    Email:  <input name="email" type="text" size="40" maxlength="50"/><br /><br />
    Message<br /><textarea name="message" cols="70" rows="30"></textarea><br /><Br />
    <input name="send" type="submit" value="Send" />
    </form>

 

PHP:

<?php

$email = 'chris@mhp.co.uk';
$return = $HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['name'];
$message = $HTTP_POST_VARS['message'];

echo "<h4>Can't send email to $email</h4>";


if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}


elseif (mail($email,$subject,$message, $return)) {
  echo "<center><h4>Thank you for sending email</h4><br><br><a href='index.html'>Click here to return to site</a></center>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>

 

But for some reason it's not working at all on a new hosting provider one of my clients has chosen. At first no variables were being passed at all, then i put a .htaccess file on the server with suphp_ConfigPath /mnt/vol1/home/s/t/stanga/ in the file and then a php.ini file on the server too with register_globals = On . This then started allowing the variables to be passed, but the mail form still isn't working.

 

I've had to cut the code down alot just for testing purposes, and it's definately passing the variables but still NOT sending the email!!

 

<?php

$email = 'chris@mhp.co.uk';
$return = $HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['name'];
$message = $HTTP_POST_VARS['main'];
$new = $HTTP_POST_VARS['phone'];
$another = $HTTP_POST_VARS['method'];
$headers .= 'To: Chris <chris@mhp.co.uk> ' . "\r\n";
$headers .= 'From: Website Test <online@test.co.uk>' . "\r\n";
$headers .= 'Cc: chris@mhp.co.uk' . "\r\n";
$headers .= 'Bcc: chris@mhp.co.uk' . "\r\n";
mail($email,$subject,$message, $headers);
echo "<a href='index.html'>Click here to go back to site</a>";
?>

 

 

Would appreciate help!!

 

peace

 

EDITED BY WILDTEEN88: Please use code tags (


) when posting code within posts. Thank you

 

 

Link to comment
Share on other sites

<?

mail("email@email.com","yo","testing");

?>

 

run that, if it doesnt work, 2 possibilities

 

1:) Web provider as disabled the mail function, which a lot do in whch case you will need to use php for smtp method

 

2:) There IP has been blacklisted by your email provider. Hotmail? If someone on there server has spammed, that server will be banned, regardless. Try sending it to a gmail account or yahoo, make sure to check junkmail aswell, they nearly always go there if send from a server

Link to comment
Share on other sites

... then i put a .htaccess file on the server with suphp_ConfigPath /mnt/vol1/home/s/t/stanga/ in the file and then a php.ini file on the server too with register_globals = On . This then started allowing the variables to be passed, but the mail form still isn't working.

 

There was no need to enable register_globals as your code does not appear to rely on this setting. However you are using old superglobal variables. Rather than $HTTP_*_VARS you should use $_* eg:

 

$HTTP_POST_VARS should be $_POST

$HTTP_GET_VARS should be $_GET

$HTTP_SERVER_VARS should be $_SERVER etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.