-
October 17th, 2003, 06:18 PM
#1
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?
-
October 17th, 2003, 06:26 PM
#2
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...
-
October 17th, 2003, 06:35 PM
#3
Member
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
-
October 17th, 2003, 06:50 PM
#4
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
-
October 17th, 2003, 07:18 PM
#5
Member
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
-
October 17th, 2003, 07:22 PM
#6
The problem was that you were assigning $mailHeaders a new value with the Reply-To line, rather than concatenating the string. I.e.:
should have been:
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!
-
October 17th, 2003, 07:25 PM
#7
Senior Member
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);
-
October 17th, 2003, 07:27 PM
#8
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
-
October 17th, 2003, 07:41 PM
#9
Senior Member
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>")
???
-
October 17th, 2003, 08:00 PM
#10
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
-
Forum Rules
|
|