Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    16

    Default php mail form works except on one account

    I have a php mail form that I have used several times without problem and it works on
    my own test site, but not on the client's site. (It doesn't send the message) We are
    both on Westhost, with Site Manager. I have php installed on both accounts (one is
    php 5.2.8 and the one that doesn't work is 5.2.14). The page that doesn't work is
    www.ibew1245.com/feedbackform3.html . It goes to the reply page, but the email never
    arrives. The code is pretty old, so I doubt it is the difference in php versions.
    We're stumped.
    (and yes, we checked the spam folder)

  2. #2
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    What method is your mail form using to send the emails? Are the correct variables set in the reply.php code? In other words are any paths or email address, passwords, usernames ect. variables set correct? Have you turned on php error logging so you can check for errors? http://wildjokerdesign.net/faq/how-c...-error-logging

    It is difficult to know without having more details of the code which is why threw out the above. Do double check paths, and variables that you can set in the script. I don't know how many times I've forgotten to change them in a script before I uploaded to a client site then spent hours running around in circles till it dawned on me. Sometimes there are some differences in versions but normally with minor version changes. Setting up error logging may catch those types of things if any.

    Oh one more thing. Are you using a "real" email address in the script and not just an alias? Look for a dead letter file in the root of the clients account. It used to be that if you used an alias account with the php mail function then it would end up in the dead letter file.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  3. #3
    Junior Member
    Join Date
    Jan 2009
    Posts
    16

    Default

    Hello Shawn, my hero from past crises.

    They say the email is "real" and it worked when I used the form on my test site.

    There are no passwords or usernames in the php, and the path between the two files is good. I can probably set up the error log, since you showed me once before about .htaccess files.

    This php form is one I have used for a long time without problem, though I don't speak php. Here is the form:
    <?php

    $destination = "proposal@ibew1245.com";

    $valid_referrer = array('www.kifergraphics.com', 'kifergraphics.com', 'www.ibew1245.com', 'ibew1245.com');

    $fields = array('proposaltype', 'name', 'classification', 'headquarters', 'homephone', 'cellphone', 'workphone', 'email', 'proposal', 'supporting','contract_section');

    $illegal_msg_chrs = array("Content-Type", "Content-type", "content-type", "<", ">");

    // Content-Type:

    $form_arr = array();

    // get form variables
    foreach ($fields as $field) {
    if (isset ($_POST[$field]))
    ${$field} = $_POST[$field];
    else
    ${$field} = "";
    }

    // get form arrays
    foreach ($form_arr as $arr) {
    if (isset ($_POST[$arr]))
    ${$arr} = $_POST[$arr];
    else
    ${$arr} = array();
    }


    $today = date("F j, Y, g:i a");

    $message = <<<END
    ****************************************
    Feedback Form, Physical Bargaining
    $today
    ****************************************
    Proposal type: $proposaltype
    From: $name
    Classification: $classification
    Headquarters: $headquarters
    Home Phone: $homephone
    Cell Phone: $cellphone
    Workphone: $workphone
    Email: $email
    Proposal: $proposal
    Supporting Arguments: $supporting
    Contract Section: $contract_section

    END;


    // remove illegal characters from message
    $message = str_replace ($illegal_msg_chrs, '', $message);

    // check for valid referral address before sending mail
    $valid_add = 0;

    foreach ($valid_referrer as $ref) {
    $pos = stripos($_SERVER["HTTP_REFERER"], $ref);
    if ($pos !== FALSE) {
    $valid_add++;
    }
    }

    if ($valid_add) {

    mail($destination, "proposal" . $subject, $message,
    "From: webform@{$_SERVER['SERVER_NAME']}\r\n"
    ."Reply-To: $email\r\n"
    ."X-Mailer: PHP/" . phpversion());

    }

    ?>

  4. #4
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    At a glance I don't see anything wrong in the code. All pretty standard PHP stuff. If the error log shows nothing then maybe start throwing in some checking in the code it self. For example at the very least you need to provide an else for your if on $valid_add. That way if for some reason the that test is not being passed you would know and could go from there.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  5. #5
    Junior Member
    Join Date
    Jan 2009
    Posts
    16

    Default

    Shawn can you tell me how this number 0 works in this line:
    // check for valid referral address before sending mail
    $valid_add = 0;

    Thanks

  6. #6
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,720

    Default

    The script runs through the variables you have added to $valid_referrer in the foreach function using strpos to check them. It then looks to see if strpos did not return false and if it did not then it increases the value of $valid_referrer but one. It then looks to see if $valid_refeffer is no longer set to 0. There are other ways you could check that if you found it was not working as expected. For example you could use in_array.

    PHP Code:
    $valid_add false;
    if (
    in_array($_SERVER["HTTP_REFERER"], $valid_referrer)) {
        
    $valid_add true;

    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  7. #7
    Junior Member
    Join Date
    Jan 2009
    Posts
    16

    Default

    Thanks, Shawn. That makes sense even though I don't "speak" php.

    We are continuing our tests and now wonder if the return address is the problem. It is created from this:
    "From: webform@{$_SERVER['SERVER_NAME']}\r\n"

    Can I replace that with a real email address? If so, which of those symbols do I leave? The email would be "webform@ibew1245.com".

  8. #8
    Junior Member
    Join Date
    Jan 2009
    Posts
    16

    Default

    I figured it out. I leave the part after the curly bracket. \r\n"

    But that didn't solve my issue, which seems to be a block between mail from the web page to a particular address. So I think it is an email problem not a form problem, and we can work around that.

    Thanks for your help, Shawn!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •