Guber-X Posted November 4, 2012 Share Posted November 4, 2012 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('guber_x@hotmail.com', 'Newsletter Confirmation', $message, 'From: noreply@fightingforyesterday.com'); 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/ Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2012 Share Posted November 4, 2012 You aren't checking whether the mail() function succeeds. if( mail( . . . Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/#findComment-1390057 Share on other sites More sharing options...
Guber-X Posted November 4, 2012 Author Share Posted November 4, 2012 hmm, i never used that with my other working mail script... i just added the checking script if(mail("guber_x@hotmail.com", "Newsletter Subscribe", $message, "FROM: noreply@fightingforyesterday.com")){ 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. Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/#findComment-1390060 Share on other sites More sharing options...
Guber-X Posted November 4, 2012 Author Share Posted November 4, 2012 hmm, would it be because im testing all this from my local server (Xampp)? Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/#findComment-1390061 Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2012 Share Posted November 4, 2012 Yes, that could be it. The mail function is successfully sending the message to the MTA, so it could be filtered off by your ISP. Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/#findComment-1390062 Share on other sites More sharing options...
Guber-X Posted November 4, 2012 Author Share Posted November 4, 2012 ISP could be blocking it or my router or net security haha. I'll toss it on my host and test it there and will let you know if it works Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/#findComment-1390063 Share on other sites More sharing options...
Guber-X Posted November 4, 2012 Author Share Posted November 4, 2012 okay, so it was cuz of my local test server haha. it works from my host. Thanks for the help Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/270267-php-mail-function-help/#findComment-1390064 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.