Problem with Mail() Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Call Me Tom

    Problem with Mail() Function

    The following simple script receives data from a form and sends me an
    email. It works fine on my testing machine (xampp for windows).
    However, when I upload it to my web host, the script processes but I
    do not receive the email. I have used two different email addresses
    and both work from the localhost and both fail from the web host. One
    email address is at verizon.net and the other at gmail.com. I have
    also checked the spam folders and the mail is not there.

    I have emailed my webhost and they say that they tried the script and
    it worked for them. They claim no problem with the server and suggest
    that I check with my software manufacturer.

    Web Host PHP version 5.2.5
    Localhost PHP version 5.2.6

    Any suggestions as to what may be going wrong?

    Thanks for your help,

    Tom

    The Script:

    <?php
    $ln=$_POST['lname'];
    $fn=$_POST['fname'];
    $em=$_POST['email'];
    $vat=$_POST['vatsim_id'];
    $city=$_POST['city'];
    $state=$_POST['state'];
    $country=$_POST['country'];
    $hub=$_POST['req_hub'];
    $req_password=$ _POST['req_password'];

    // Send email to Tom Rushworth with details from pilot application

    $mailto="?????? ?@gmail.com";
    $mailsubject="C AA - New Member Application";
    $mailbody ="An application to join CAA was completed with the
    following information:" . "\n" . "\n";
    $mailbody .= "Last name: " . $ln . "\n";
    $mailbody .= "First name: " . $fn . "\n";
    $mailbody .= "Email Address: " . $em . "\n";
    $mailbody .= "VATSIM ID: " . $vat . "\n";
    $mailbody .= "City: " . $city . "\n";
    $mailbody .= "State: " . $state . "\n";
    $mailbody .= "Country: " . $country . "\n";
    $mailbody .= "Hub: " . $hub. "\n";
    $mailbody .= "Password Requested: " . $req_password . "\n";

    mail("$mailto", "$mailsubje ct", "$mailbody" , "CAA NEW MEMBER
    ANNOUNCEMENT");

    // Retrurn to application

    header("Locatio n: pilot_applicati on.php?app_subm itted=yes");

    ?>
  • Krustov

    #2
    Re: Problem with Mail() Function

    <comp.lang.ph p>
    <Call Me Tom>
    <Tue, 19 Aug 2008 17:38:03 -0400>
    <u6ema4dqlh6mka eqcjpdili5qjmc8 nfnua@4ax.com>
    Any suggestions as to what may be going wrong?
    >
    ini_set("sendma il_from","webma ster@rambo.co.u k");
    ini_set("SMTP", "pop.rambo.co.u k");

    I once had some windows hosting where i had to use the above 2 lines
    before the mail() command would work .

    Although the chances are your using linux hosting .

    But the point is it might be a configuration problem that can be fixed
    with 'whatever' one line of ini_set code .


    --

    Comment

    • WalterGR

      #3
      Re: Problem with Mail() Function

      On Aug 19, 2:38 pm, Call Me Tom <No...@nowhere. netwrote:
      The following simple script receives data from a form and sends me an
      email. It works fine on my testing machine (xampp for windows).
      However, when I upload it to my web host, the script processes but I
      do not receive the email. I have used two different email addresses
      and both work from the localhost and both fail from the web host. One
      email address is at verizon.net and the other at gmail.com. I have
      also checked the spam folders and the mail is not there.
      >
      I have emailed my webhost and they say that they tried the script and
      it worked for them. They claim no problem with the server and suggest
      that I check with my software manufacturer.
      >
      Web Host PHP version 5.2.5
      Localhost PHP version 5.2.6
      >
      Any suggestions as to what may be going wrong?
      >
      Thanks for your help,
      >
      Tom
      >
      The Script:
      >
      <?php
      $ln=$_POST['lname'];
      $fn=$_POST['fname'];
      $em=$_POST['email'];
      $vat=$_POST['vatsim_id'];
      $city=$_POST['city'];
      $state=$_POST['state'];
      $country=$_POST['country'];
      $hub=$_POST['req_hub'];
      $req_password=$ _POST['req_password'];
      >
      // Send email to Tom Rushworth with details from pilot application
      >
      $mailto="????.. .@gmail.com";
      $mailsubject="C AA - New Member Application";
      $mailbody ="An application to join CAA was completed with the
      following information:" . "\n" . "\n";
      $mailbody .= "Last name: " . $ln . "\n";
      $mailbody .= "First name: " . $fn . "\n";
      $mailbody .= "Email Address: " . $em . "\n";
      $mailbody .= "VATSIM ID: " . $vat . "\n";
      $mailbody .= "City: " . $city . "\n";
      $mailbody .= "State: " . $state . "\n";
      $mailbody .= "Country: " . $country . "\n";
      $mailbody .= "Hub: " . $hub. "\n";
      $mailbody .= "Password Requested: " . $req_password . "\n";
      >
      mail("$mailto", "$mailsubje ct", "$mailbody" , "CAA NEW MEMBER
      ANNOUNCEMENT");
      >
      // Retrurn to application
      >
      header("Locatio n: pilot_applicati on.php?app_subm itted=yes");
      >
      ?>
      When sending mail, you must supply a "From: " header. One way to do
      it has already been mentioned on this thread: using the sendmail_from
      configuration setting.

      Another way to do it is to supply it via the 4th parameter to the
      mail() function. What does "CAA NEW MEMBER
      ANNOUNCEMENT" in your script mean? The 4th parameter needs to
      contain proper MIME-encoded e-mail headers, which means something like
      "From: nobody@example. com".

      So a possible way to debug your script would be: since it works fine
      locally, take a look and see who the "From:" address is when you
      receive the e-mail. If it's something you didn't specify anywhere in
      your script, then it's probably being set via the sendmail_from
      configuration setting.

      (Also, depending on how your host is set up, additional e-mail headers
      may be required. For example: on my web host, I have to set the
      "Return-Path:" header in addition to the "From:" header. If I don't
      set it, the e-mail doesn't get sent.)

      Hope that helps.

      Walter


      Comment

      • Ulf Kadner

        #4
        Re: Problem with Mail() Function

        Call Me Tom wrote:
        email. It works fine on my testing machine (xampp for windows).
        However, when I upload it to my web host, the script processes but I
        do not receive the email.
        Thats not the real Problem of youre code!
        The code dont check and filter bad data by any way. Better put it to
        your trash or repair it.

        Comment

        • C. (http://symcbean.blogspot.com/)

          #5
          Re: Problem with Mail() Function

          On 20 Aug, 09:40, Ulf Kadner <dr_lo...@gmx.n etwrote:
          Call Me Tom wrote:
          email. It works fine on my testing machine (xampp for windows).
          However, when I upload it to my web host, the script processes but I
          do not receive the email.
          >
          Thats not the real Problem of youre code!
          The code dont check and filter bad data by any way. Better put it to
          your trash or repair it.
          Not a problem since only hardcoded stuff is going in the headers - the
          posted data only appears in the body. As long as he's not daft enough
          to try and use MS Outlook it'll work fine.

          It's overkill for debugging though - and as an illustration of what
          does not work:

          OP - cut down your code to the minimum necessary to reproduce the bug
          before posting.

          e.g.

          <?php
          mail("...@examp le.com", "hello world", "testing", "CAA NEW MEMBER
          ANNOUNCEMENT");
          ?>

          Although it may not be the reason its failing, your additional headers
          are crap. Email headers should of type "label: value" where label is a
          contigious string of letters, digits, hyphens and underscores -
          further, if the label is not one of the declcared types in the
          relevant RFCs, it should be prefixed by 'X-' e.g.

          <?php
          mail("...@examp le.com", "hello world", "testing", "X-test: CAA NEW
          MEMBER
          ANNOUNCEMENT");
          ?>


          C.

          Comment

          • PHPGB

            #6
            Re: Problem with Mail() Function

            <comp.lang.ph p>
            <C. (http://symcbean.blogsp ot.com/)>
            <Wed, 20 Aug 2008 09:10:21 -0700 (PDT)>
            <f226db59-f27f-4371-b65a-995c49974d5e@a7 0g2000hsh.googl egroups.com>
            OP - cut down your code to the minimum necessary to reproduce the bug
            before posting.
            >
            But if hes kinda new to php - and asking the question - then how does he
            know one way or the other what code he should or shouldnt include ? .


            --

            (the best php guestbook on planet earth)

            Comment

            • Call Me Tom

              #7
              Re: Problem with Mail() Function

              On Wed, 20 Aug 2008 09:10:21 -0700 (PDT), "C.
              (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.comwrote :
              >On 20 Aug, 09:40, Ulf Kadner <dr_lo...@gmx.n etwrote:
              >Call Me Tom wrote:
              email. It works fine on my testing machine (xampp for windows).
              However, when I upload it to my web host, the script processes but I
              do not receive the email.
              >>
              >Thats not the real Problem of youre code!
              >The code dont check and filter bad data by any way. Better put it to
              >your trash or repair it.
              >
              >Not a problem since only hardcoded stuff is going in the headers - the
              >posted data only appears in the body. As long as he's not daft enough
              >to try and use MS Outlook it'll work fine.
              >
              >It's overkill for debugging though - and as an illustration of what
              >does not work:
              >
              >OP - cut down your code to the minimum necessary to reproduce the bug
              >before posting.
              >
              >e.g.
              >
              ><?php
              mail("...@examp le.com", "hello world", "testing", "CAA NEW MEMBER
              >ANNOUNCEMENT") ;
              >?>
              >
              >Although it may not be the reason its failing, your additional headers
              >are crap. Email headers should of type "label: value" where label is a
              >contigious string of letters, digits, hyphens and underscores -
              >further, if the label is not one of the declcared types in the
              >relevant RFCs, it should be prefixed by 'X-' e.g.
              >
              ><?php
              mail("...@examp le.com", "hello world", "testing", "X-test: CAA NEW
              >MEMBER
              >ANNOUNCEMENT") ;
              >?>
              >
              >
              >C.
              Thanks for the comments and suggestions. It turns out that the code
              woks fine. However, I do agree that the fourth parameter should be
              proper headers and I have changed the code to correct that.

              It turns out that the problem was that Verizon was blocking all email
              from my host's server (at least the one that I am on) as spam. They
              contacted Verizon and all is now OK.

              Comment

              Working...