PHP mail not being recieved

The following code was working. But now isn't the only change I am aware of is the isp who has moved to php 5. They are saying other people are having no problems but I am not recieving emails at all and do not appear to be getting as far as the header request. Any ideas?

<?php
$id = $_GET['id'];

if (Isset($send) && $send == "contact") {//then the contact us page has been filled out

      $from = $email;

      $emailTo = "mike.cocklin@gmail.com";

      $subject = "Contact Us Request from Expensys Website";

      $body = "The following details were entered on the Expensys Website\n\n";

      $body .= "Name: " . $txtname . "\nCompany: " . $company . "\nTelephone: " . $tele . "\n";

      $body .= "Fax: " . $fax . "\nEmail: " . $email . "\nThey have requested the following:\n";

      if (Isset($onsite) && $onsite == "1") {

            $body .= "On-site Expensys Presentation\n";

      }

      if (Isset($costred) && $costred == "1") {

            $body .= "Cost Reduction Health Check\n";

      }

      $body .= "End of mail.";

      mail(

            $emailTo,

            $subject,

            $body,

            $from

      );

      Header("Location: index.php?id=8&sent=true");

}
mikecocklinAsked:
Who is Participating?
 
glcumminsCommented:
Ah, I see. You are depending on 'register_globals' being enabled. This is not the default behavior in PHP 5, and is a security risk if it is enabled.

Rather than expecting your variables to be populated automatically, you need to do it manually as you suggested in your last post. At the top of your script, add:

 $email = $_REQUEST['email'];

and repeat for each variable that needs to be populated.
0
 
glcumminsCommented:
>> code was working. But now isn't

What exactly is not working? Are you receiving an error? Do you see error messages in the mail server logs? Is the message being marked as spam on the receiving end?
0
 
mikecocklinAuthor Commented:
Basically the page is reloading with an empty form. There are no error messages and the logs say nothing is being sent.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mikecocklinAuthor Commented:
It appears that it is not reading the fields from the form properly. Ie if I use $_REQUEST['email']; etc etc it seems fine but if i just use $email etc etc it doesn't but it did in php 4. Can this have anything to do with global variables being of or something?
0
 
grahamnonweilerCommented:
It looks like they have register_global OFF - which is the standard way of working for PHP5.

Assuming you are using the GET method for your form change your code as shown below:

<?php
$id = $_GET['id'];

if ($_GET[' $send ']== "contact") {//then the contact us page has been filled out

$from = $_GET['$email'];

$emailTo = "mike.cocklin@gmail.com";

$subject = "Contact Us Request from Expensys Website";

$body = "The following details were entered on the Expensys Website\n\n";

$body .= "Name: " . $_GET['$txtname'] . "\nCompany: " . $_GET['$company'] . "\nTelephone: " .$_GET[' $tele'] . "\n";

$body .= "Fax: " . $_GET['$fax' ]. "\nEmail: " . $_GET['$email'] . "\nThey have requested the following:\n";

if ($_GET['$onsite'] == "1") {

$body .= "On-site Expensys Presentation\n";

}

if ($_GET['$costred] == "1") {

$body .= "Cost Reduction Health Check\n";

}

$body .= "End of mail.";

mail($emailTo,$subject,$body,$from);

Header("Location: index.php?id=8&sent=true");

}

If you are using the POST method for your form them use $_POST instead.



0
 
mikecocklinAuthor Commented:
OK

One of the forms has about 50 checkboxes (Nightmare) and another has about 30. So is there a way to set register_globals to enabled for just one or 2 directories? That would save me having to rewrite the code. (written some years ago by another developer) not my ideal solution, as I am sure you can imagine.
0
 
ahincCommented:
Have you checked that the SMTP and smtp_port setting are correct (Windows) or that sendmail_path is correct (unix) in php.ini?
0
 
glcumminsCommented:
No, the only place to change it is in the php.ini file. You can try dropping a php.ini file in each of the directories with 'register_globals = On', but most PHP installations override this.
0
 
ahincCommented:
Posted my last comment several minutes too late. You do not want to enable globals as it quickly becomes a security nightmare on any form open to the outside world. If the checkboxes follow any type of similar naming (ie: checkbox_1, checkbox_2, etc) you could use a loop to read the values.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.