php - Email confirmation sending -


i'm trying implement email confirmation newsletter subscription app. if user inputs valid data , added database, code goes:

else {          $insert = $db -> prepare ("insert newsletter (name, email, cfkey, time) values(:name, :email, :cfkey, now())");         $insert -> execute(array(':name' => $name, ':email' => $email, ':cfkey' => $cfkey));                                                  //success! - notify user          $usermsg  = '<br /><br /><h4><font color="0066ff">thanks ' . $name . ', have been added successfully.</font></h4>';          $name = "";         $email = "";      }// end else        $mail_body = '<html>                     <head>                     <title>my name</title>                     </head>                      <body>                      <p style="color: green";>hello ' . $name . ',</p>                     <div>please confirm subscription - http://www.domain.com/activation.php?key=$cfkey </div>                     <p>~the temam</p>                      </body>                 </html>';      $subject = "subsc";     $headers  = "from: domain@domain.com\r\n";     $headers .= "content-type: text/html\r\n";     $to = "$email";      $mail00 = mail($to, $subject, $mail_body, $headers); }  if ($insert) {     echo "inserted in db";   }  else {     echo "not inserted in db"; } /* if ($mail00) {     echo "<br>email sent!</br>"; } else {     echo "<br>email not sent</br>"; } */  ?> 

earlier in code, cfkey-generator declared:

$cfkey = md5 ($email . rand()); // generate random hash value 

the "activation.php" scripts goes this:

<?php  ////database connection ****  //declare value $key = $_get['cfkey'];   $confirm = $db -> prepare ("select * newsletter email=?"); $confirm-> bindvalue(1, $email); $confirm -> execute ();  while($row = mysql_fetch_array($confirm)){      $db_key = $row ['cfkey'];      }  if ($key == $db_key) {     $db -> exec ("update newsletter set confirmed='1'");     $db -> exec ("update newsletter set cfkey='0'");      echo "thank you!"; }  else {     echo "email confirmation not valid"; }  ?> 

after user enters email, stored in database, along unique confirmation key. i've been @ week , have 2 problems:

1.email isn't being sent inputted email address. if set "to" field specific email (e.g. name@domain.com") email sent , received. however, above code sends email not received.

2.email never verified. code above doesn't seems work - when email received unique cfkey, after clicking on it "not verified".


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -