Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: PHP mail-function

  1. #1
    Banned
    Join Date
    Aug 2001
    Location
    Yes
    Posts
    4,424

    PHP mail-function

    I'm having a little problem here...
    I'm starting up my own e-business, and I'm writing it all myself (in PHP).

    To sign up, users must provide their name, email, pick a username and a password.
    After they click the "submit"-link, an email is sent to the mailaddress they provided, and that's where the problem is situated...

    Here's my code:

    Code:
    $mailSubject = "Confirm Your membership.";
                    $mailBody =  "Hi $firstname $lastname,\n";
                    $mailBody .= "\n";
                    $mailBody .= "Thank you for joining ********\n";
                    $mailBody .= "\n";
                    $mailBody .= "Please click the following link to confirm your membership. If clicking does\n";
                    $mailBody .= "not work, please copy and paste into your browser manually.\n";
                    $mailBody .= "\n";
                    $mailBody .= "http://*****.***.**\n";
                    $mailBody .= "\n";
                    $mailBody .= "Thank you.\n";
                    $mailHeaders = "From: postmaster@neg.be \n";
                    $mailHeaders = "ReplyTo: postmaster@neg.be \n";
    
                    mail($email, $mailSubject, $mailBody, $mailHeaders);
    The mail is sent, but the problem seems to be in the headers... the mail seems to be coming from anonymous@priorweb.be.... That's pretty cool, but there is no anonymous@priorweb.be (that address doesn't exist). And it should be coming from postmaster@neg.be.

    I'm guessing that there is something wrong with my headers (or the formatting). Priorweb is my host, so I'm guessing (again) that they decline my headers and assign the anonymous-thingy to it... any suggestions?

  2. #2
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953
    hm, that's weird... the syntax you [posted should be working? have you tried removing that extra line brake at the end of the headers?
    yeah, I\'m gonna need that by friday...

  3. #3
    maybe u can get some hints from these to e-mail forms:
    - contactme from www.stevedawson.com - free, its very configurable, and easy to do it.

    or allstuffmailer from http://www.Frenck.nl - also free, didnt try it

    or do a search on www.scriptsearch.com

    good luck

  4. #4
    Banned
    Join Date
    Aug 2001
    Location
    Yes
    Posts
    4,424
    This is weird... I took out the $Mailheader variables and manually added them in the script, and it works now...

    Code:
    $mailSubject = "******** - Confirm Your membership.";
                    $mailBody =  "Hi $firstname $lastname,\n";
                    $mailBody .= "\n";
                    $mailBody .= "Thank you for joining ********!\n";
                    $mailBody .= "\n";
                    $mailBody .= "Please click the following link to confirm your membership. If clicking does\n";
                    $mailBody .= "not work, please copy and paste into your browser manually.\n";
                    $mailBody .= "\n";
                    $mailBody .= "http://********.***.**\n";
                    $mailBody .= "\n";
                    $mailBody .= "Thank you.\n";
    
                    mail($email, $mailSubject, $mailBody, "From: postmaster@neg.be");
    That's what you get for using variables

  5. #5
    Member
    Join Date
    Jul 2002
    Posts
    41
    Perhaps $mailheader is being used by the hosting company as a global php variable which would override a local one, if I'm not mistaken....perhaps try it with a rephrased variable name
    -Those are my principles. If you don\'t like them, I have others.
    --Groucho Marx

  6. #6
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    The problem was that you were assigning $mailHeaders a new value with the Reply-To line, rather than concatenating the string. I.e.:

    Code:
    $mailHeaders = "From: postmaster@neg.be \n";
    $mailHeaders = "ReplyTo: postmaster@neg.be \n";
    should have been:

    Code:
    $mailHeaders = "From: postmaster@neg.be \n";
    $mailHeaders .= "ReplyTo: postmaster@neg.be \n";
    If you want to be even more fancy, you can do this:

    Code:
    $mailHeaders = "From: Negative <postmaster@neg.be> \n";
    which will show up as your name in most email clients/web based interfaces. It's a bit more friendly than an email address (you can replace Negative with say "Postmaster" or whatever you want).

    I got fed up of messing with the headers manually whenever I wanted to send mail, so I wrote a class to do the work for me. Now all I have to do is call the appropriate method (i.e. sender_email($email, $name)) and it adds the headers automatically. The source code is available if you want to see how it's done.

    BTW, the ReplyTo field is a bit redundant IMO if you're going to set it to the same value as the From field.

    Oh, and if a value isn't specified for the From: field (as it wasn't in your case, because you were overwriting the string with the ReplyTo: field), PHP will use whatever's defined in php.ini. I used to get emails from 'nobody@f2o.org' before I figured out how to fix this (I'd accidentally put the To: headers in the wrong place, or used From: twice or something like that).

    Hope this helps!
    Paul Waring - Web site design and development.

  7. #7
    Senior Member
    Join Date
    Aug 2003
    Posts
    185
    I'm pretty noob on php but interested in...

    would you like to try this?
    Code:
    $mailHeaders = "From: postmaster@neg.be \n";
    $mailHeaders = "<postmaster@neg.be> \n";
    
    mail($email, $mailSubject, $mailBody, $mailHeaders);

  8. #8
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    Originally posted here by stanger
    I'm pretty noob on php but interested in...

    would you like to try this?
    Code:
    $mailHeaders = "From: postmaster@neg.be \n";
    $mailHeaders = "<postmaster@neg.be> \n";
    
    mail($email, $mailSubject, $mailBody, $mailHeaders);
    stanger:
    a) I've already pointed that out
    b) You've made the same (albeit easy to make) mistake as Negative, you're overwritting the value of $mailHeaders with the second assignment as opposed to concatenating the string
    Paul Waring - Web site design and development.

  9. #9
    Senior Member
    Join Date
    Aug 2003
    Posts
    185
    hmmm...
    a) i was to slow
    b) however...
    that php file is the wrong place to set the email reply address
    (if things go to database and $postmastermail should be global)

    mail($email, $mailSubject, $mailBody, $mailHeaders, $postmastermail)

    would this work?

    or should be:

    mail($email, $mailSubject, $mailBody, $mailHeaders "<$postmastermail>")
    ???

    Industry Kills Music.

  10. #10
    Banned
    Join Date
    Aug 2001
    Location
    Yes
    Posts
    4,424
    Mr. Waring, you are a genius... or I'm an airhead, whichever works...
    Thank you! Problem solved

Posting Permissions

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