I am trying to send a email everytime a customer sign-up using my form. I want the email to work in the background. I have created a mysql database and set the form/webpage. How would I go about making this. Is there a way to send a email in the background everytime a user signs up?

Member Avatar for LastMitch

I am trying to send a email everytime a customer sign-up using my form. I want the email to work in the background. I have created a mysql database and set the form/webpage. How would I go about making this. Is there a way to send a email in the background everytime a user signs up?

I'm confused what are you trying to do? What do you mean you want a email to work in the background? Did you mean a image in the background of the email? Can you explain more about the email in the background?

I have a form and mysql database setup to recive information. After they register I want an email to be send to me informing me with there information(name,phonen number, email)

Member Avatar for LastMitch

@jdgrinder

I have a form and mysql database setup to recive information. After they register I want an email to be send to me informing me with there information(name,phonen number, email)

You just want the data that was submitted to the database at the same time, it will send data to you too? Is that what you want?

Then you should used $_POST & $_GET function. Read this:

http://www.tizag.com/phpT/postget.php

This $_POST function will post the data in the message and email the data to you.

This $_GET function will get the data in the message and email the data to you.

You can used either function and it will work.

You can used the example from the link as a guideline.

Member Avatar for Zagga

$_POST and $_GET are arrays, they won't actually email anything to you. You will probably need the php mail function for this.

Member Avatar for LastMitch

@jdgrinder

You can used Zagga mail function as an alternative or you can used this:

http://www.freecontactform.com/email_form.php

This example has a basic PHP script which will capture the form submissions and send the form contents to your email address.

This example will be more clearer than the one I just post before because I only gave you an general idea or outline on how a Post works.

Here is the code. Where would I put the mail function or $_get ?

function register(){


//Connecting to database

$connect = mysql_connect("127.0.0.1", "username", "password");

if(!$connect){

die(mysql_error());

}


//Selecting database

$select_db = mysql_select_db("bbhyd_sms", $connect);

if(!$select_db){

die(mysql_error());

}


//Collecting info

$name = $_REQUEST['name'];

$phone = $_REQUEST['phone'];

$email = $_REQUEST['email'];

$date = $_REQUEST['date'];


//Here we will check do we have all inputs filled


if(empty($name)){

die("Please enter your name!<br>");

}


if(empty($phone)){

die("Please enter your password!<br>");

}


if(empty($pass_conf)){

die("Please confirm your password!<br>");

}


if(empty($email)){

die("Please enter your email!");

}


//Let's check if this username is already in use


$user_check = mysql_query("SELECT username FROM users WHERE username='$username'");

$do_user_check = mysql_num_rows($user_check);


//Now if email is already in use


$email_check = mysql_query("SELECT email FROM users WHERE email='$email'");

$do_email_check = mysql_num_rows($email_check);


//Now display errors


if($do_user_check > 0){

die("Username is already in use!<br>");

}


if($do_email_check > 0){

die("Email is already in use!");

}


//Now let's check does passwords match


if($password != $pass_conf){

die("Passwords don't match!");

}



//If everything is okay let's register this user


$insert = mysql_query("INSERT INTO users (name, phone, email) VALUES ('$name', '$phone', '$email')");

if(!$insert){

die("There's little problem: ".mysql_error());

}
Member Avatar for LastMitch

@jdgrinder

Read the link I just send you:

http://www.freecontactform.com/email_form.php

Read this

The PHP Code which captures and Emails your website form

It show you how to POST forget GET function.

Just take some of the code and put it in your code.

Member Avatar for Zagga

Hi jdgrinder,

You already have your form so you just need to actually send the email. Add this code after everything you posted (line 122).

// Set your email address.
$admin_email = "your_email@address.com";

// Set email headers.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: " . $admin_email . "\r\n" . "Reply-To: " . $admin_email . "\r\n";

// Set the email body (Do NOT use double quotes inside the email body).
$email_body = "
<html>
<head>
<title>My Form</title>
</head>
<body>
<div>
<h1>My Form Results</h1><br />
$name Filled in your form.<br />
$name's phone number is $phone<br />
$name's email address is $email
</div>
</body>
</html>
";

// Send email using the variables we just set.
mail("$admin_email", "My Form Was Filled In", "$email_body", "$headers");

I strongly suggest that you escape the user supplied data before you put it in your database, and that you convert the data to a safer format before you email it.

Thanks Zagga and lastmitch for all the help.

Member Avatar for LastMitch

@jdgrinder

Is it's solve? If so can you click Mark Question Solve on the bottom left corner so the thread is close and solve so noone can add stuff to it. Thanks.

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.