SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: PHP and mail()

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    When I am trying to send my form to my e-mail, when it sends it doesn't submit the results.
    IE.
    name =
    E-Mail =

    Here is my source
    My E-mail is changed.:

    <?PHP
    Include ("top.php");


    if ($submit) {
    while(list($key,$val) = each ($HTTP_POST_VARS)) {
    $body .= $key ." = ". $var ."\n";
    }
    echo("$var");
    mail("myemail", "form submission", $body);
    }
    ?>



    <img src="contact.jpg" width="150" height="35" border="0" alt=""><P><P>

    <table>
    <tr>
    <td width="300" bgcolor=#CCCC99>
    <font face="Arial,Helvetica,sans-serif" size="2" color="Black">
    You can e-mail me, the webmaster, at the address below or fill out the form.</a>
    </font>
    </td>
    </tr>
    </table>

    <form action="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <table width="300" cellspacing="5" cellpadding="5">
    <tr>
    <td valign="top">
    <font face="Arial,Helvetica,sans-serif" size="2">
    Name
    </font>
    </td>
    <td><input type="text" name="name" size="30"><p></td>
    </tr>
    <tr>
    <td valign="top">
    <font face="Arial,Helvetica,sans-serif" size="2">
    E-Mail
    </font>
    </td>
    <td><input type="text" name="e-mail" size="30"></td>
    </tr>
    <tr>
    <td>
    <font face="Arial,Helvetica,sans-serif" size="2">
    Comments
    </font>
    </td>
    <td><textarea cols="30" rows="8" name="comments">
    </textarea></td>
    </tr>
    </table>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="submit">


    </form>







    <?PHP
    Include ("bottom.php");
    ?>


    Thanks for any help.

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try giving the $body variable a value before the while loop, it may be giving you trouble because you're appending the variable (with ".=") before giving it any value.

    Worth a shot.

  3. #3
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure what your problem is, but I think using foreach() would be a better solution. Try:
    Code:
    <?
    foreach($HTTP_POST_VARS as $key => $value)
    {
        $foo .= sprintf('%s = %s\n',$key,$value);
    }
    echo $foo
    ?>

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would that change things?

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing except for with robp's method the newline would not have show up due to the single quotes in the printf() statement. You are sure the form is getting posted? Are you just hitting the enter key or actually clicking on the submit button.

    if ($name) {
    while(list($key,$val) = each ($HTTP_POST_VARS)) {
    $body .= $key ." = ". $var ."\n";
    }
    mail("myemail", "form submission", $body);
    }


    That way if the submit button is not getting clicked the script will still recognize that it has been submitted.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried both hitting enter and clicking the submit button. Both times the same result:
    name =
    e-mail =
    comments =
    submit =

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why I didn't notice it earlier but you use $val in the while statement and then $var in the $body .= statement they must be the same thus your code should look like this:
    while(list($key,$val) = each ($HTTP_POST_VARS)) {
    $body .= $key ." = ". $val ."\n";
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'OH!


Bookmarks

Posting Permissions

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