matthew798 Posted September 9, 2010 Share Posted September 9, 2010 It just so happens that I have never used the PHP mail() function and i believe i've hit my first major snag. So if any of you brilliant minds out there can just take a second to error check the following code id GREATLY appreciate it! The db is connected earlier and i KNOW all the vars work because the script worked before i stuck in the mail() section. //REVISE else{ $q = mysql_query("INSERT INTO account (Username, Firstname, Lastname, Email, Active, User_type, User_language, User_registration, Pass) VALUES('$username', '$firstname', '$lastname', '$email', '$active', '$type', '$language', '$today', '$password')") or die(mysql_error()); $id = mysql_query("SELECT id FROM account WHERE Username = '$username'"); $message = "Welcome to the exciting world of Star Wars Galaxies : A New Hope! Your new username is ".$username."! Please click the following link or paste it in a web browser to complete the activation process. HTTP://www.swganh.com/account_activate.php?id=".$id;//LANGINSERT $headers = "From: [email protected]\r\n"; mail($email, 'SWG:ANH New account registration/confirmaton', $message, $headers);//LANGINSERT } The problem is that im just not getting a mail when i send it to myself... No errors, but no mail either. Thanks in advance guys! Quote Link to comment https://forums.phpfreaks.com/topic/212919-help-with-mail-function/ Share on other sites More sharing options...
pornophobic Posted September 9, 2010 Share Posted September 9, 2010 I know that I'm not really answering your question, but instead of using the PHP's mail(), I prefer to use PEAR's SMTP class. This is because it's a bit less confusing when you figure it out by reading documentation and if you use an SMTP account (On your own server, or even your gmail) there is much less of a chance of your site's emails being sent to junk boxes because the mail header is signed. Quote Link to comment https://forums.phpfreaks.com/topic/212919-help-with-mail-function/#findComment-1108973 Share on other sites More sharing options...
ocpaul20 Posted September 9, 2010 Share Posted September 9, 2010 So..you need to copy and paste the email example from the manual and work from there. I always try to start from basics and build up to what I want. If the sql stuff worked, thats a good start, so isolate a mail test program and try that. make sure you are receiving mail first, then stick the working code into your program and run it to make sure you are still receiving mail. Then modify the mail statement to send what you need it to send. Quote Link to comment https://forums.phpfreaks.com/topic/212919-help-with-mail-function/#findComment-1108977 Share on other sites More sharing options...
Rifts Posted September 9, 2010 Share Posted September 9, 2010 Who is your hosting provider? Quote Link to comment https://forums.phpfreaks.com/topic/212919-help-with-mail-function/#findComment-1108980 Share on other sites More sharing options...
DavidAM Posted September 9, 2010 Share Posted September 9, 2010 $headers = "From: [email protected]\r\n"; mail($email, 'SWG:ANH New account registration/confirmaton', $message, $headers);//LANGINSERT 1) Check your From address above. You have two ".com"s in there. 2) Check the return code from the mail() function 3) Do you have error reporting on? i.e. error_reporting(E_ALL); ini_set("display_errors", 1); -- You might be getting a message that could help explain the problem. 4) Check your Junk mail folder In my opinion, if the mail() function is succeeding (returns true), the most likely problem is the From address you are using. Let's say your website is "www.mydomain.com" and your From address is "[email protected]". Your server might NOT send the message at all because the From domain is not your domain - this is a SPAM indicator and your host does NOT want to get marked as permitting spam. IF your server SENDS the message, your email server may flag it as SPAM because the addresses do not match, and it may be in your spam filtered box - I suppose your email server could just refuse delivery. The short answer is to always specify a From address that belongs to the server that is sending the mail; i.e. [email protected]. Except for the second ".com", it looks like your From address is your server, so that should be OK. You might try removing the "\r\n" from the end of the $headers; I don't think you need it on the last header (and you have only one). You might also try changing it to just a new-line ("\n") -- that's not valid according the the specs, but there are some misbehaved agents out there that automatically inject the carriage-return before the newline. On one of my development boxes (which I had not configured correctly), I had to add the additional parameter of "-f [email protected]" specifically matching the server. So you might try: mail($email, 'SWG:ANH New account registration/confirmaton', $message, $headers, '-f [email protected]');//LANGINSERT Quote Link to comment https://forums.phpfreaks.com/topic/212919-help-with-mail-function/#findComment-1108997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.