Jump to content

Php Mail Function Help!


Guber-X

Recommended Posts

So for this project im working on I have a newsletter subscription for the website, when a user submits their email address it is sent to the database and as well a "eMail" is sent to the user with a activation link. I wanted this activation link to limit emails being sent to bots, spiders and all that crap thats not done by humans....

 

anyways. so I have used this mail function before and works great, but for some reason the only thing my script is not doing is sending the email and I can't seem to figure out why.

and yes thats why i am here lol... i figured to have a couple other sets of eyes look at my code and see if i missed something.

 

CODE:

<?php
$em = $_POST['em'];
$status = "OK"; // setting the flag to check the status
$msg="";		 // setting the variable for message

 if (!stristr($em,"@") OR !stristr($em,".")) {
	 $msg="Your email address is not correct: ".$em."<BR>";
$status= "NOTOK";
 }
 if($status=="OK"){ // Now the email is valid and we can add to our database
$activation = md5(uniqid(rand(), true));
	 $query=("INSERT INTO nl_subscribe (em,status) VALUES ('$em','$activation')");
	 $result=mysql_query($query);
 // Send the email:
	 $message = ' To activate your account, please click on this link:\n\n';
	 $message .= ' FULL URL HERE activate.php?email=' . urlencode($em) . '&key='.$activation;
	 mail('[email protected]', 'Newsletter Confirmation', $message, 'From: [email protected]');
echo '<center>THANK YOU '.$em.'<br>Thanks for subscribing to our newsletter and any time you can unsubscribe by clicking a link in your newsletter</center>';
 }
 else {echo "<center>$msg </center>";} // this will display the error message if email address is not valid one.
?>

Link to comment
https://forums.phpfreaks.com/topic/270267-php-mail-function-help/
Share on other sites

hmm, i never used that with my other working mail script...

 

i just added the checking script

 

if(mail("[email protected]", "Newsletter Subscribe", $message, "FROM: [email protected]")){
   echo "Mail Sent";
} else {
   echo "Mail Error";
}

 

and when i submit it does say "Mail Sent" but does not show in the email account anywhere.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.