• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

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");

}
0
mikecocklin
Asked:
mikecocklin
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now