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

Recommended Answers

All 8 Replies

Member Avatar for dan_ord

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.

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");
	}
		
?>
Member Avatar for dan_ord

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

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

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

I have write this code for a nomination page. it's working but the only problem is the mail is sending to only the mentioned email it does not return
any message or confirmation image or anything to those client who filling the form and mentioned their email in the email section.

Please help me for how to add those confirmation to those who filling the form.

<?php
if(isset($_POST['submit']))

curly braces start

  $msg='Name: '.$_POST['name']."\n"

  .'Gender: '.$_POST['gender']."\n"
  .'Birthday: '.$_POST['bday']."\n"
  .'Email: '.$_POST['email']."\n"
  .'Phone: '.$_POST['phone']."\n"
  .'Jobtittle: '.$_POST['Design']."\n"
  .'Company: '.$_POST['company']."\n"
  .'Address: '.$_POST['Address']."\n"
  .'Country: '.$_POST['country']."\n"
  .'AwardCategory: '.$_POST['awardcategory']."\n"
  .'Sector: '.$_POST['sector'];
  mail('Swarnabharatparivaarps@gmail.com','Nomination Form',$msg);

  header('location: register_update.php');

curly braces end
else
curly braces start

  header('location: nomination.php');
  exit(0);

curly braces end
?>

Amaresh_1, that's not how it works. You buried your question in some 8+ year old dead discussion. If you want folk to get in there, don't bury your questions like this.

Pls where is the code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.