SitePoint Sponsor

User Tag List

Results 1 to 24 of 24

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I don't know how to fix, email from.

    Hi, I have a strange problem and don't know how to fix it, but it is very important to get it fixed, because the form won't send without it. For some reason the form won't send unless the form field "requesteremail" has data in it and I don't know why. So I thought if I just put an error command if the field was empty everything would work anyway, because people would be prompted to fill in the field. But when I add the "if empty" statement, for some reason it is also ignored, unless something is in the "requesteremail" field. I don't get it, it makes no sense to me, but I really need it fixed. Hope someone will help. Thank you very much.


    PHP Code:
    while ($row = mysql_fetch_array($result)){
    if ($_POST['websitename']==""){?>

    <form method="post" action="<?php $_SERVER['PHP_SELF'] ;?>">
    <input type="hidden" value="<?php echo $row[websitename];?>" name="websitename">
    <input type="text" name="requesteremail" size=20>
    <input type="text" name="page" size=20>
    <input type="submit" name="submit" value="Submit" /></form>
    <?php 
    }
    else{
    $mailto 'emailaddress@something.com' 
    $subject "Subject of email" ;
    $websitename $_POST['websitename'] ; 
    $requesteremail $_POST['requesteremail'] ; 
    $page $_POST['page'] ; 
    $uself 0;
    $sep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" "\n" ;
    $messageproper "$websitename\n" "$requesteremail\n" "$page\n";
    mail($mailto$subject$messageproper"From: \"$requesteremail\" <$requesteremail>" $sep "Reply-To: \"$requesteremail\" <$requesteremail>" $sep);
    if (empty(
    $requesteremail) || empty($requesterwebsite)) {echo "field empty please try again";}
    else {echo 
    "email sent!";}
    }}}
    //these 3 brackets needed from other mysql variables earlier.
    ?>
    Last edited by 1Jen; Jan 11, 2007 at 21:44.

  2. #2
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use \r\n as lines separator in the mail body too.

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Does that help my problem?

  4. #4
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It can be the reason of email not being sent. Check out php.net mail() manual page, there is a better explanation for this in user comments.

  5. #5
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    error

  6. #6
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure these are separated in the body. See my $messageproper. Everything shows in the body fine, unless the $requesteremail is empty.

  7. #7
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You actually use different variables: $requesteremail and $requestermail.

  8. #8
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that was just a typo in this forum, for the body of the email, thats not it. Anyone know how I can fix this problem? Thank you very much.

  9. #9
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to wrap the call to mail() in your if/else logic

  10. #10
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That seems odd, can you tell me why? I don't understand why the if empty isn't working on that field.

  11. #11
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your condition works fine. you fail to do anything with it.

    Code:
    if (condition) {
        put code here you want executed when condition is true
    } else {
        put code here you want executed when condition is false
    }

  12. #12
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Depending on your php version and server, you must specify an address in the FROM header, if your variable $requesteremail is empty you are not, and the mail wont be sent.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  13. #13
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That must be the problem mandes because nothing else makes sense. Clam the else won't work as well. What I don't understand is regardless of whether or not it satisfies the "from" for the email, why won't the "if else" work if the field is empty? If I understand why the "If" empty isn't working, then I'll know where to go from here. Anyone who knows a lot about php, know the answer? Thanks.

  14. #14
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 1Jen View Post
    That must be the problem mandes because nothing else makes sense.
    From the php manual

    additional_headers (optional) String to be inserted at the end of the email header.

    This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).
    Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

    Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.




    Markl999 has suggested why your if logic isnt working, seems that your 2 problems perhaps aren't linked to each other at all
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  15. #15
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (empty($requesteremail) || empty($requesterwebsite)) 
    Your code never mentions $requesterwebsite before that point, so unless you've defined it elsewhere that will cause the 'if' to be true.
    $requesterwebsite sounds like it should be $websitename to me, but it's anyones guess.

    If I wasn't in such a good mood I'd suggest a rethinking of the whole logic of your code

  16. #16
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good thinking mark but adding the other variable didn't help. I still don't know why the "if" statement isn't executing before it trys to send the email.

  17. #17
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the first if should really be more like:
    if (!empty($_POST['websitename'])){?>
    ..to avoid errors/warnings etc.

    The second 'if' comes after the mail() command so has no effect on sending the mail or not.

  18. #18
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this is the weirdest thing, I put this before the rest of the email code.

    else{
    $requesteremail = $_POST['requesteremail'] ;
    if(!$_POST['requesteremail']){echo "Please enter a valid email address.";}
    else{echo "email sent";}
    $mailto = 'emailaddress@something.com' ; etc. and so on.

    When the requesteremail is empty, it still won't show an echo, but when something is put in the requesteremail it says "email sent" just like it is supposed to. Why won't it honor the first echo but will the second?????

    But if I do it with any other field besides requesteremail both the if and else echo's work. Guess that can only mean I have to put something in that field as a default.

    So how can I add a default "if, else" to this?
    if(!$_POST['requesteremail'])
    {
    $requesteremail = "the field was never filled";
    }

    Isn't working.

    Mandes info from the manual says I should be getting a missing header error message and I'm not, but maybe that doesn't mean anything.

  19. #19
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try this

    Code:
     
    if($_POST['requesteremail']== ''){
    echo 'no value in field';
    }else{
    echo 'value=' . $_POST['requesteremail'];
    }
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  20. #20
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are using the correct words, like 'empty' .. just not applying them to your code
    Don't do:
    if(!$_POST['requesteremail'])
    if you mean:
    if(empty($_POST['requesteremail']))

    (as it may not even be set. empty() will check that too)

  21. #21
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope Mandes, didn't work, but thanks for trying. Once again it used the echo when filled, but not the if empty. This is the funniest thing yet not funny I have ever seen. Mark, can you elaborate? I was told if(!$_POST['requesteremail'])
    and
    if(empty($_POST['requesteremail']))
    means the same thing.

    So I read a bit more about mandes tip from the manual and it says I should use the additional headers to help.

    $eol="\r\n";
    $header =. 'From: MyName<'.$requesteremail.'>'.$eol;
    $headers .= 'Reply-To: MyName<'.$requesteremail.'>'.$eol;
    $headers .= "X-Mailer: PHP v".phpversion().$eol;

    But once again if requesteremail is empty I'm dead in the water. Also the headers the manual gives are not ready and not concatenated. Does anyone know how to concatenate the just above headers? It looks like I need an additional header wiz that knows about this problem. None of the normal fixes are working.

  22. #22
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you sure your not chasing your own tail here, as I understand it, your primary problem was that the email didnt sent when the requesteremail variable was blank, but you seem to have got sidetracked on working on conditional statements now.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  23. #23
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its finally working!!! The headers helped. I just removed the dot after this
    $headers .

    Thankyou Mandes, thank you everybody! I'll send you something. Man that was something.

  24. #24
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •