Jump to content

help with mail function


matthew798

Recommended Posts

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: matt@swganh.com.com\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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

	$headers = "From: matt@swganh.com.com\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 "Kevin.Flynn@mcp.com". 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. website@mydomain.com.

 

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 myname@myhost.com" specifically matching the server. So you might try:

 

mail($email, 'SWG:ANH New account registration/confirmaton', $message, $headers, '-f matt@swganh.com');//LANGINSERT

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.