<?
$name = $POST['name'];
$wherehear = $
POST['wherehear'];
$contactnumber = $POST['contactnumber'];
$email = $
POST['email'];
$message = $_POST['message'];

$body = "$name used the contact page\n\nName: $name\nReffered: $wherehear\nPhone_Number: $contactnumber\nEmail: $email\n\n$message";

mail( "mail@somewhere.com", "Message from website",
$bodystuff, "From: $email");

header( "Location: a_page.html" );
?>

    I've already been there but it didn't help me very much as I'm pretty sure my syntax is correct.

    Thats why I posted here to see if there was something more detailed I need or could try.

    Still open to suggestion.

    Cheers.

      First, try getting as much debug info as you can out of your script:

      <?php
      ini_set('display_errors', 1);
      error_reporting(E_ALL);
      //
      // ...yadda yadda yadda
      //
      $result = mail("mail@somewhere.com", "Message from website",
      $bodystuff, "From: $email");
      if($result == FALSE)
      {
         die("call to mail() failed");
      }
      header( "Location: a_page.html" );
      ?>
      

      PS: You might want to read up on email injection attacks, and avoid using "unsanitized" form values in your mail() command.

        One thing I just noticed is that you are using a value from the form as the "From:" email address. Most servers will require that the "From:" email address be a valid address on that server, not just any email address. (This is to prevent spammers from using it as a mail relayer.) What you will probably need to use is a valid email address for the "From:" header, then add a "Reply-To:" header that uses the user-supplied email as its value (after you have sanitized it, of course).

          Ah yes I've read this in other forums and yes I am using a valid email, I'm just not putting it for obvious spam reasons.

          Trying your new code now.

          Thx.

            My hosting site is really giving me hassles atm so this could take some extra timeπŸ™

              Ok, sorry NogDog but it would appear that my hosting site is doing some updating or some such so I can't login correctly at the moment so I'll just have to try your code later.

              Thanks anyway.

              Don't be afraid to post other ideas, idle onlookers. πŸ˜ƒ

                Ok ran through your code a few times changing little pieces as they complained about incorrect variables, however, no matter what I do I always get a "call to mail() failed" message. This leads me to think that there is a server side problem.

                I'm using this code.

                <?php 
                ini_set('display_errors', 1); 
                error_reporting(E_ALL); 
                // 
                // ...yadda yadda yadda 
                // 
                $result = mail("my_email@hotmail.com", "Message from website", 
                "body of da message", "From: okemail@address"); 
                if($result == FALSE) 
                { 
                   die("call to mail() failed"); 
                   echo("failed");
                } 
                header( "Location: a_page.html" ); 
                ?>

                and just get one line with the call to mail() failed on it. http://webguardians.awardspace.com/mailerrors.php

                So if there is something I can do that will check my server settings I'm open to it. You can check my phpinfo at http://webguardians.awardspace.com/test.php

                Me thinks a more experienced code will see where my problem lies.

                Cheers.

                  Just to make sure, is the email address which follows "From: " in the last parameter to mail() a valid email address on your web host? (If it is not, the vast majority of sendmail configurations will reject the mail attempt as invalid.)

                    Sorry NogDog I'm not sure what you mean.

                    "From: " email@address.com IS valid (it's one of mine) so it does exist and gets email regularly or do you mean that my host may not allow emails from any random "From" address and that I may need to tell it one to make this work. Asin I find a server setting and tell it to allow this@email.com?

                    Thanks for your patience with me πŸ˜ƒ

                      The "From:" email address must be an address that exists on the same host where your script is running. The host's sendmail function will check to see if the from address is valid on its host, otherwise it will reject the message as an attempt to use its host as a mail relay (a tactic used by some spammers to obfuscate the source of their emails). Therefore, if you are sending mail from a script running at "www.yourhost.com", then the "From:" email address will typically need to be an email address configured for your web host domain, e.g.: "info@yourhost.com" or "your_name@yourhost.com". It cannot be "someone@yahoo.com" or "no_one@gmail.com".

                        Ah I understand now. Well this is going to be a problem for me because I am currently running on a sub-domain, so I cant have my own email account πŸ™

                        However I believe this must be my problem so when I upgrade (I plan to soon), it will be on my list to get an email account along with it.

                        Thanks for your help NogDog but I dont think there is anything more I can do at this time.

                        Mods can set this to RESOLVED.
                        Thanks again NogDog!

                          Write a Reply...