We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
mail() help
Topic Started: Jun 19 2005, 06:32 PM (899 Views)
Dennis
Member
[ *  *  *  *  *  *  * ]
I've been coding a referral program for a site I Admin, and I've run into a problem with sending an E-Mail confirming registration. Here's the code:

Quote:
 
 
  if($query)
  {
    $query = "SELECT * FROM hits WHERE email = '$email'";
    $result = mysql_query($query);
    $num_results = mysql_num_rows($result);
    {
  while ($row = mysql_fetch_assoc($result))
  {
    $id = "{$row['id']}";
  }
    }
    $mailcontent = "This E-Mail is in regards to a registration received for the Alienation Skins referral Program using this E-Mail address.\n \n If you did not register an account, or have received this E-Mail in error, please ignore it or forward it to cheating@alienationskins.com \n \n.
    To use your Referral Program, please use the following link:\n \n
   
    http://alienationskins.com/index.php?id=$id \n \n
   
    Thanks, and good luck. \n   
    - The Alienation Skins Team.";
          $headers = 'From: referral@alienationskins.com';
    mail('$email', 'Alienation Skins Referral Program Confirmation','$mailcontent','$headers');
    echo 'Referrer added successfully! You should receive an E-Mail shortly containing your ID, along with further instructions on the use of your account. If you do not receive this E-Mail, please contact Special Forces or Dennis. Thank you.';
  }


It does not throw any errors, and the message displays fine, but the E-Mail is never received. Any ideas what I've done wrong?

This is only the E-mail part of the file. I can give you the rest, but it's rather long.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Is this code to e-mail everybody? I am a bit of a n00b here, but:

Quote:
 
  while ($row = mysql_fetch_assoc($result))

This would insinuate yo uare e-mailing everyone in that row.
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
Quote:
 
QUOTE

  if($query)
  {
    $query = "SELECT * FROM hits WHERE email = '$email'";
    $result = mysql_query($query);
    $num_results = mysql_num_rows($result);
    {
  while ($row = mysql_fetch_assoc($result))
  {
    $id = "{$row['id']}";
  }
    }
    $mailcontent = "This E-Mail is in regards to a registration received for the Alienation Skins referral Program using this E-Mail address.\n \n If you did not register an account, or have received this E-Mail in error, please ignore it or forward it to cheating@alienationskins.com \n \n.
    To use your Referral Program, please use the following link:\n \n
 
    http://alienationskins.com/index.php?id=$id \n \n
 
    Thanks, and good luck. \n 
    - The Alienation Skins Team.";
          $headers = 'From: referral@alienationskins.com';
    mail('$email', 'Alienation Skins Referral Program Confirmation','$mailcontent','$headers');
    echo 'Referrer added successfully! You should receive an E-Mail shortly containing your ID, along with further instructions on the use of your account. If you do not receive this E-Mail, please contact Special Forces or Dennis. Thank you.';
  }


What is the value of $email?
Why is that stray curly bracket there?

That loop you have there will only set $id to one value when it's done as it will be constantly overwrite it by the next value in the table. I can't really tell much more because of the stray curly bracket and not knowing how the value of $email is set.

EDIT: Email filters may be causing unsuccessful delivery as well. You can usually fix this by altering your email headers.
Offline Profile Quote Post Goto Top
 
pingu2k4
Member
[ *  * ]
what does this code do by the way, does it collect info from a form?
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Quote:
 
if($query)
  {
    $query = "SELECT * FROM hits WHERE email = '$email'";
    $result = mysql_query($query);
    $num_results = mysql_num_rows($result);
  while ($row = mysql_fetch_assoc($result))
  {
    $id = "{$row['id']}";
  }
    $mailcontent = "This E-Mail is in regards to a registration received for the Alienation Skins referral Program using this E-Mail address.\n \n If you did not register an account, or have received this E-Mail in error, please ignore it or forward it to cheating@alienationskins.com \n \n.
    To use your Referral Program, please use the following link:\n \n
 
    http://alienationskins.com/index.php?id=$id \n \n
 
    Thanks, and good luck. \n 
    - The Alienation Skins Team.";
          $headers = 'From: referral@alienationskins.com';
    $mailing = mail('$email', 'Alienation Skins Referral Program Confirmation','$mailcontent','$headers');
if($mailing)
{
    echo 'Referrer added successfully! You should receive an E-Mail shortly containing your ID, along with further instructions on the use of your account. If you do not receive this E-Mail, please contact Special Forces or Dennis. Thank you.';
}
else
{
echo 'Some text for if mailing did not work.';
}

  }


I added/changed the stuff thats blue.
Now, you can see if it actually mails.
(Happend to me that it didn't error, but didn't mail eighter)

And those 2 brackets made no sence.
(Yes, 2)
Quote:
 
$num_results = mysql_num_rows($result);
  {
  while ($row = mysql_fetch_assoc($result))
  {
    $id = "{$row['id']}";
  }
}

They don't do anything. :/
So removed them :P

If it won't mail, try a easier mailing script.
(Just to test if mail() is enabled on the server. Some have it turned off :/ )
If mail() does work, but this still doesn't, let it echo the contens of $email to see if that is set right.
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
@ Fear Killer:

The value of E-Mail is $_POST['email']

@Qj:

The part you removed is the part that fetches the id from the database.

The thing I'm having trouble with is that it worked fine before. Then we switched hosts, so it may be that. but it may also be that I changed something. I'm not sure. I'm waiting for a reply from the host.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
This is gonna' sound really stupid, but I have done it before. Are all you forms and there corresponding $_POST['']'s matching up?
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
The Balrog
June 20, 2005 04:26 PM
@Qj:

The part you removed is the part that fetches the id from the database.

No its not :/
Those {} started right after mysql_num_rows(), which is not a loop-starting function.
It only sets the amount of rows of the query to $num_results.
In this case, its not needed at all.


If all that changed is the host, see if it has mail() enabled.
Just do something like:
Code:
 

$mail = mail('some@mail.com','Testmail -> Checking if mail() works','If you are reading this, mail() works :)','From: Me@mail.com');
if($mail)
{
echo 'Mail() works :)';
}
else
{
echo 'That stupid new host won\'t let me use mail()';
}

It will let you know if you can use mail()
(Because like I said: Some hosts have mail() disabled because its being abused a lot or because its to much work for there servers or something)
Offline Profile Quote Post Goto Top
 
solinent
Member
[ *  *  * ]
or if they were playing around with it, there might of been some relay problems.

Did you try it locally?
Offline Profile Quote Post Goto Top
 
bttfpromo
LUEser.......
[ *  * ]
Code:
 
   mail('$email', 'Alienation Skins Referral Program Confirmation','$mailcontent','$headers');


Use....

Code:
 
   mail($email, 'Alienation Skins Referral Program Confirmation',$mailcontent,$headers);
Offline Profile Quote Post Goto Top
 
solinent
Member
[ *  *  * ]
Nah, that won't work. It's the same thing. Just try it locally.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Little note on the locally trying:
You would have to install a mailserver program for that.
Most php progs I know don't have something for that build in.
(Is php progs the right name btw? I mean the prog that lest you do php on your own pc by surfing to localhost.)

Damn I'm sounding stupid here.
Offline Profile Quote Post Goto Top
 
solinent
Member
[ *  *  * ]
OH yeah. If you install iis with php, then you get a virutal mailserver, as I dont' use apache. Whatever.
Offline Profile Quote Post Goto Top
 
blakeo_x
Member Avatar
I cant believe its not PHP!
[ *  *  * ]
This may be a little off-topic, but my experiences with mail() have been bad as far as security. Most of the time the email gets intercepted by a spambot and then the person being emailed gets 1,000 extra bulk emails per day.

Im not sure how to fix it as I havent looked into it that much. But, just to give you a heads-up ;)
Offline Profile Quote Post Goto Top
 
solinent
Member
[ *  *  * ]
100% why I use asp...

It's easier to use too...

it's like this:
<%
set myMail = Server.CreateObject("Mail.CDO")
myMail.From = "me@example.com"
myMail.To = "you@example.com"
myMail.HtmlBody = "<h1> Hey What is up Dude!!! </h1>"
myMail.Subject = "Sup?"
'send the mail
myMail.Send
%>

It's ppretty secure. I've never been intercepted.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1