0

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.

//email function 
ini_set("SMTP", "smtp.server.com");//confirm smtp

$to=$email;

// Your subject
$subject="activation required";

// From
$header="from: test email <Test@test.com>";

// 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);
//Create INSERT query
	$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')";
	$result = @mysql_query($qry);
	
	//add sms code here - 
	
	//add send to email - 
	
	//Check whether the query was successful or not
	if($result) {
		header("location: register-success.php");
		exit();
	}else {
		die("Query failed2");
	}
		
?>

If i could get a reply on this and some points to learn from I would be very much appreciated,

Regards
Lloyd

3
Contributors
5
Replies
29
Views
7 Years
Discussion Span
Last Post by dhanashekaranr
0

Hi,

I've taken a simple emailer off w3schools:

<?php
$to = "$email";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$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:

#
//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.

0

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

//Create INSERT query
	$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')";
	$result = @mysql_query($qry);
	
	//add sms code here - 
	
	//add send to email - 
	
	//Check whether the query was successful or not
	if($result) {
	  ini_set("SMTP", "smtpout.secureserver.net");//confirm smtp
      $to = "$email";
      $subject = "Test mail";
      $message = "Hello! This is a simple email message.";
      $from = "someonelse@example.com";
      $headers = "From: $from";
      mail($to,$subject,$message,$headers);
      	
		header("location: register-success.php");
		exit();
	//}else {
		//die("Query failed2");
	}
		
?>
0

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?

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

0

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

0

//email function
ini_set("SMTP", "smtp.server.com");//confirm smtp

$to=$email;

// Your subject
$subject="activation required";

// From
$header="from: test email <Test@test.com>";

// 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);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.