953,485 Members Technology Publication meets Social M edia
JOIN DANIWEB MEMBER LOGIN
Search
Hardware & Software
Software Development
Web Development
Internet Marketing
Business Exchange
Community Center
Web Development > PHP > send email after successfully registering a new user Have something to say? Contribute New Article Reply to this Article
LloydFarrell
Junior Poster 101 posts since Dec 2009
2 Years Ago
send email after successfully registering a new user
Hi all, this is my first post and would appreciate some insight as to where im going wrong. I have the following form that successfully registers a new user to my mysqsl database via PHP - with the following $sql INSERT Function The problem im having is sending the activation \ confirmation email to the new users email address.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.
//email function ini_set("SMTP", "smtp.server.com");//confirm smtp $to=$email; // Your subject $subject="activation required"; // From $header="from: test email <[email protected]>";
// Your message $message="Your Comfirmation link\r\n"; $message.="Click on this link to activate your account\r\n"; 15. $message.="You can not login to your new account until you have confirmed your activation\r\n"; 16. $message.="http://test.com/activationconfirmation.php?passkey=$securecode"; 17. 18. // send email 19. $sentmail = mail($to,$subject,$message,$header); 1. //Create INSERT query 2. $qry = "INSERT INTO members3t(securecode, firstname, lastname, login, passwd, email, mobnum,country,city,datetime,uipa,ref,browser,sms) VALUES('$securecode','$fname','$lname','$login','".md5($_POST['password'])."','$email','$mobnum','$country','$city','$datetime','$uipa','$ref','$browser','$sms')"; 3. $result = @mysql_query($qry); 4. 5. //add sms code here 6. 7. //add send to email 8. 9. //Check whether the query was successful or not 10. if($result) { 11. header("location: register-success.php"); 12. exit(); 13. }else { 14. die("Query failed2"); 15. } 16. 17. ?>
If i could get a reply on this and some points to learn from I would be very much appreciated, Regards Lloyd
Ads by Google
$2 Domain Names
Best Value In The Market $2, Limited Time Offer! www.Register.com
dan_ord
Light Poster 30 posts since Aug 2009
2 Years Ago Hi, I've taken a simple emailer off w3schools:
1. 2. 3. 4. 5.
<?php $to = "$email"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "[email protected]";
converted by Web2PDFConvert.com
6. 7. 8. 9.
$headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>
That should work, just change the above text to what you want to use. Also i see that after your INSERT query you sending out the email to the user. What i would do is move the emailing function further down your script and place it here:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
# //Check whether the query was successful or not # if($result) { // PUT EMAIL FUNCTION HERE -------- **** header("location: register-success.php"); # exit(); # }
Because that way it will only send out the email if the information was inserted correctly into the database. At current if it were working you would be sending out an email regardless of whether the information got inserted correctly or not. I think that's right, i'm not a php guru so apologies if i do get it wrong, but above code should work for you. Regards, Dan.
LloydFarrell
Junior Poster 101 posts since Dec 2009
2 Years Ago HI dan, thanks for your help and input, BUT im still having problems sending emails after inserting data into my mysql database, The data still inserts correctly, but the script is still not sending emails Can anyone help please
1. //Create INSERT query 2. $qry = "INSERT INTO members3t(securecode, firstname, lastname, login, passwd, email, mobnum,country,city,datetime,uipa,ref,browser,sms) VALUES('$securecode','$fname','$lname','$login','".md5($_POST['password'])."','$email','$mobnum','$country','$city','$datetime','$uipa','$ref','$browser','$sms')"; 3. $result = @mysql_query($qry); 4. 5. //add sms code here 6. 7. //add send to email 8. 9. //Check whether the query was successful or not 10. if($result) { 11. ini_set("SMTP", "smtpout.secureserver.net");//confirm smtp 12. $to = "$email"; 13. $subject = "Test mail"; 14. $message = "Hello! This is a simple email message."; 15. $from = "[email protected]"; 16. $headers = "From: $from"; 17. mail($to,$subject,$message,$headers); 18. 19. header("location: register-success.php"); 20. exit(); 21. //}else { 22. //die("Query failed2"); 23. } 24. 25. ?>
dan_ord
Light Poster 30 posts since Aug 2009
2 Years Ago Have you tried going to your control panel and checking your error log? You've probably already done this, but if you haven't it definitely worth a try. Also do you need the following line in your code?
1. ini_set("SMTP", "smtpout.secureserver.net");//confirm smtp
Is that something which your hosting requires for you to send an email? If not take it out, might be causing your problem. Regards, Dan
LloydFarrell
Junior Poster 101 posts since Dec 2009
2 Years Ago Hi Dan, The script is now sending email ;-) I had to create a new email address to use as the sending email address, That part im not too sure about, Thanks for your help, I will confirm this by selecting "resolved" cheers Lloyd
converted by Web2PDFConvert.com
dhanashekaranr
Newbie Poster 1 post since Sep 2010
1 Year Ago //email function ini_set("SMTP", "smtp.server.com");//confirm smtp $to=$email; // Your subject $subject="activation required"; // From $header="from: test email "; // Your message $message="Your Comfirmation link\r\n"; $message.="Click on this link to activate your account\r\n"; $message.="You can not login to your new account until you have confirmed your activation\r\n"; $message.="http://test.com/activation-confirmation.php?passkey=$securecode"; // send email $sentmail = mail($to,$subject,$message,$header);
You
This question has already been solved
Post: Bold Italic
Code Inline Code
Markdown Syntax: Formatting Help Link Quote Heading Sub-Heading # List List
U n do Redo
Reply to this Article (Alt+S)
0
Tweet
Web Development > PHP
Share
View similar articles that have also been tagged: activation email php send
access ajax apache api array asp.net blog button c# chat checkbox code codeigniter contact convert css data database date development dynamic echo email error expression file files form forms framework function help! htaccess html html5 image images it-pro java javascript joomla jquery json jsp learn link links login loop mail multimedia multiple
mysql mysql-query oracle outlook page pages pagination parse pdf
php phpmailer post problem programming query radio redirect regex registration regular
script search security select send server session sessions size sms smtp sql string syntax table text time update upload url user variable variables vb.net web website wordpress xml
2012 DaniWeb LLC Home | About Us | Contact Us | Terms of Service | Advertising Opportunities RSS Feed
Recently Updated Articles
Join the DaniWeb Community
converted by Web2PDFConvert.com