RazzleDazzle Posted July 19, 2011 Share Posted July 19, 2011 I have mostly followed a tutorial, as I am only a beginner with PHP...I want the 'user' to sign up with their email. Then they automatically receive an email from us about our company. The email address is also going to be saved in a mySQL database. So far I have been able to save the data but I can not get the code to send an email to the 'user' email address... Any suggestions...?? FYI I have changed my password in the code so I'm not hacked, that is not what's wrong with my code Thank you [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/242377-mysql-database-email-signup-form/ Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 would you mind pasting the code to this thread please. Quote Link to comment https://forums.phpfreaks.com/topic/242377-mysql-database-email-signup-form/#findComment-1244971 Share on other sites More sharing options...
reyborn Posted July 20, 2011 Share Posted July 20, 2011 You can make this code as reference: $to = "email_where_the_message_will_be_send"; $subject = "Te_subject_of_your_email"; $message = "Dear User, \r\n\r\n"; $message .= "This is your message \r\n"; $headers = "From: your@email.com \r\n"; mail($to,$subject,$message,$headers); Quote Link to comment https://forums.phpfreaks.com/topic/242377-mysql-database-email-signup-form/#findComment-1244974 Share on other sites More sharing options...
RazzleDazzle Posted July 20, 2011 Author Share Posted July 20, 2011 <?php include_once 'inc/php/config.php'; include_once 'inc/php/functions.php'; //setup some variables/arrays $action = array(); $action['result'] = null; $text = array(); //check if the form has been submitted if(isset($_POST['signup'])){ //cleanup the variables //prevent mysql injection $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $email = mysql_real_escape_string($_POST['email']); //quick/simple validation if(empty($username)){ $action['result'] = 'error'; array_push($text,'You forgot your username'); } if(empty($password)){ $action['result'] = 'error'; array_push($text,'You forgot your password'); } if(empty($email)){ $action['result'] = 'error'; array_push($text,'You forgot your email'); } if($action['result'] != 'error'){ $password = md5($password); //add to the database $add = mysql_query("INSERT INTO `users` VALUES(NULL,'$username','$password','$email',0)"); if($add){ //get the new user id $userid = mysql_insert_id(); //create a random key $key = $username . $email . date('mY'); $key = md5($key); //add confirm row $confirm = mysql_query("INSERT INTO `confirm` VALUES(NULL,'$userid','$key','$email')"); if($confirm){ //include the swift class include_once 'http://ryanafonk.com/imag-design/source/inc/php/swift/swift_required.php'; //put info into an array to send to the function $info = array( 'username' => $username, 'email' => $email, 'key' => $key); //send the email if(send_email($info)){ //email sent $action['result'] = 'success'; array_push($text,'Thanks for signing up. Please check your email for confirmation!'); }else{ $action['result'] = 'error'; array_push($text,'Could not send confirm email'); } }else{ $action['result'] = 'error'; array_push($text,'Confirm row was not added to the database. Reason: ' . mysql_error()); } }else{ $action['result'] = 'error'; array_push($text,'User could not be added to the database. Reason: ' . mysql_error()); } } $action['text'] = $text; } ?> <?php include 'inc/elements/header.php'; ?> <?= show_errors($action); ?> <form method="post" action=""> <fieldset> <ul> <li> <label for="username">Username:</label> <input type="text" name="username" /> </li> <li> <label for="password">Password:</label> <input type="password" name="password" /> </li> <li> <label for="email">Email:</label> <input type="text" name="email" /> </li> <li> <input type="submit" value="Signup Now" class="large blue button" name="signup" /> </li> </ul> </fieldset> </form> <?php include 'inc/elements/footer.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242377-mysql-database-email-signup-form/#findComment-1245271 Share on other sites More sharing options...
RazzleDazzle Posted July 20, 2011 Author Share Posted July 20, 2011 @reyburn....where would I put that code?? On my Config.php file? Or somewhere on this index.php file? Quote Link to comment https://forums.phpfreaks.com/topic/242377-mysql-database-email-signup-form/#findComment-1245272 Share on other sites More sharing options...
fenway Posted July 22, 2011 Share Posted July 22, 2011 And with code tags, next time. Quote Link to comment https://forums.phpfreaks.com/topic/242377-mysql-database-email-signup-form/#findComment-1246235 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.