I have this link and then processed by this script:
<html>
<head>
</head>
<?php
/*//Disable error reporting
error_reporting(0);
*/
//Report runtime errors
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
//<script>location.replace("http://www.mntr.xxx.com/update.php");</script>
//Report all errors
error_reporting(E_ALL);
//end of error reporting
if(isset($_POST['submit']) && $_POST['submit'] == 'Send') {
//var_dump($_POST['users']);
$size= sizeof($_POST['users']);
$i = 0;
$message = NULL;
// $message = null;
for($i=0; $i<$size; $i++){
$userId = $_REQUEST['users'][$i];
$message .= mailContent($userId);
}
$to = $_POST['email'];
$subject = 'This is a test';
$headers = 'From: xxx#live.com.ph' . "\r\n" .
'Reply-To: xxx#live.com.ph' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';
mail($to, $subject, $message, $headers);
}
function mailContent($userId) {
$con=mysqli_connect("localhost","xxx","xxx","xxx");
$stmt = "SELECT * from CV where idvisa = '$userId'";
$result = mysqli_query($con, $stmt);
$row=mysqli_fetch_array($result);
$fName = $row['fName'];
$lName = $row['lName'];
$visaNumber = $row['visanumber'];
$idNumber = $row['idnumber'];
$statusApp = $row['statusapp'];
$accntVisaPhotoPath = $row['accntVisaPhotoPath'];
$passportPath = $row['passportPath'];
$message = "Your Username: YOUR EMAIL (small caps) PASSWD: 1234
<table>
<tr>
<td>Name</td><td>$fName $lName</td>
</tr>
<tr>
<td>CVs</td><td>Click Here</td>
</tr>
<tr>
<td>Visa Number</td><td>$visaNumber</td>
</tr>
<tr>
<td>ID Number</td><td>$idNumber</td>
</tr>
<tr>
<td>Application Status</td><td>$statusApp</td>
</tr>
<tr>
<td>Visa Copy</td><td><a href='http://mntr.xxx.com/".$accntVisaPhotoPath."'>Click to Download</a></td>
</tr>
<tr>
<td>Passport Copy</td><td><a href='http://mntr.xxx.com/".$passportPath."'>Click to Download</a></td>
</tr>
</table>";
// OTHER LOGICS GO HERE
return $message;
}
//Additional var
//Time
date_default_timezone_set('Asia/Manila');
//End Time
$email = $_POST['email'];
$subdate = date("Y-m-d");
$subdate2 = date("Y-m-d");
if (empty($subdate)) {
$sql="UPDATE CV SET subdateEmail='$email',subdate='$subdate WHERE idvisa='$userId'";
} else {
$sql="UPDATE CV SET subdateEmail2='$email',subdate2='$subdate2' WHERE idvisa='$userId'";
}
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "<center>You have sent CV(s) </b><br/><br/><br/><br/>YOU MAY NOW CLOSE THIS WINDOW</center>";
?>
It is working but I want to update 4 columns out of the selected users (in this case, idvisa) AFTER email. Right now, it doesn't update. I am thinking on the array that has been SELECTED.
Any idea?
Use this
error_reporting(E_ALL);
$con=mysqli_connect("localhost","xxx","xxx","xxx");
if(#mail($to, $subject, $message, $headers))
{
ate_default_timezone_set('Asia/Manila');
//End Time
$email = $_POST['email'];
$subdate = date("Y-m-d");
$subdate2 = date("Y-m-d");
if (empty($subdate)) {
$sql="UPDATE CV SET subdateEmail='$email',subdate='$subdate WHERE idvisa='$userId'";
} else {
$sql="UPDATE CV SET subdateEmail2='$email',subdate2='$subdate2' WHERE idvisa='$userId'";
}
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "<center>You have sent CV(s) </b><br/><br/><br/><br/>YOU MAY NOW CLOSE THIS WINDOW</center>";
}else{
echo "Mail Not Sent";
}
Related
im trying to send mail in php,so that mail receiver receives mail with html table, im receiving mail with table but data is missing in mail.. im recieving variable instead of data from html form.
Name: $name
Email: $email
Phone: $phone
Services: $services
Address: $address
Subject: $subject
Message: $message
The code i write is below
<?php
$name = $email = $address = $phone = $service = $subject = $message ="";
$contactErr = "";
$contactsuccess = "";
if (isset($_POST['submit'])) {
$fm_name = $_POST['name'];
$fm_email = $_POST['email'];
$fm_address = $_POST['address'];
$fm_phone = $_POST['phone'];
$fm_service = $_POST['service'];
$fm_subject = $_POST['subject'];
$fm_message = $_POST['message'];
$name = contact_input($fm_name);
$email = contact_input($fm_email);
$address = contact_input($fm_address);
$phone = contact_input($fm_phone);
$service = contact_input($fm_service);
$subject = contact_input($fm_subject);
$message = contact_input($fm_message);
if (empty($fm_name)) {
$contactErr = "Name is Required.";
}
elseif (empty($fm_email)) {
$contactErr = "Email. is Required.";
}
elseif (!filter_var($fm_email, FILTER_VALIDATE_EMAIL)) {
$contactErr = "Invalid email format";
}
elseif (empty($fm_address)) {
$contactErr = "Enter you address.";
}
elseif (empty($fm_phone)) {
$contactErr = "Phone No. is Required.";
}
elseif (empty($fm_service)) {
$contactErr = "Select your desired service !";
}
elseif (empty($fm_subject)) {
$contactErr = "Subject is Required.";
}
elseif (empty($fm_message)) {
$contactErr = "Enter your message!";
}
else{
$info = '<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<table border="1" cellspacing="3" width="60%">
<tr>
<td>Name:</td>
<td>$name</td>
</tr>
<tr>
<td>Email:</td>
<td>$email</td>
</tr>
<tr>
<td>Address:</td>
<td>$address</td>
</tr>
<tr>
<td>Phone:</td>
<td>$phone</td>
</tr>
<tr>
<td>Subject:</td>
<td>$subject</td>
</tr>
<tr>
<td>Services:</td>
<td>$service</td>
</tr>
<tr>
<td>Message:</td>
<td>$message</td>
</tr>
</table>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mailto = "satish.innovstudio#gmail.com";
$sub = "Get In Touch With Us";
mail($mailto,$sub,$info,$headers);
$contactsuccess = "Your message has been sent successfully! We will contact you shortly.";
$name = $email = $address = $phone = $service = $subject = $message ="";
}
}
function contact_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
You have all of your variables just written out in the string. You're going to need to concatenate them.
instead of
<td>$message</td>
it should be
<td>.$message.</td>
Just change the ' to " at the start and end of $info variable string declaration (you then need to escape every " character in your string or change it to ') OR change your variables to, for example, '. $name .'.
In single quotes variables are not interpreted as they are in double quoted strings.
Read answer to this question about the difference between single and double quotes in PHP strings to get what you are doing wrong:
https://stackoverflow.com/a/3446286/15182618
Im trying to send an email to 2 variables currently I have tried to add 3 emails to an array and put that into a variable and get the other email from the form, I then dont know how to put both of those variables together when sending so they each have their own "to" but this does not work or something doesnt and I dont know what?? And yes I have real emails that I use these are placeholders for this!!!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['submit'])) {
$email = $_POST['LOGSE'];
$email2 = array("test#test.com", "test#test.com", "test#test.com");
$name = $_POST['full_name'];
$eventtitle = $_POST['EventT'];
$InCharge = $_POST['InCharge'];
$Venue = $_POST['Venue'];
$VenY = $_POST['VenR'];
if($VenY != "Yes"){
$ava = " Have not checked if";
}
else{
$ava = "";
}
$dates = $_POST['dateS'];
$datee = $_POST['dateE'];
$adults = $_POST['Adults'];
$children = $_POST['Children'];
$catreq = $_POST['CateReq'];
if (catreq != ''){
$catreq = $catreq;
}
else{
$catreq = "No Catering Needed";
}
$logreq = $_POST['LogReq'];
if (logreq != ''){
$logreq = $logreq;
}
else{
$logreq = "No Logistic Equipment Needed";
}
$itreq = $_POST['ITReq'];
if (itreq != ''){
$itreq = $itreq;
}
else{
$itreq = "No IT Needed";
}
$tran = $_POST['TransR'];
if($tran != Yes){
$tran = "NO ";
}
else{
$tran = "";
}
$Risk = $_POST['RiskR'];
if($Risk != Yes){
$Risk = "NO ";
}
else{
$Risk = "";
}
$othern = $_POST['OtherN'];
// The Email:
$from = 'test#test.com';
$to = $email;
$to = $email2;
$subject = 'Event Form ' .$eventtitle;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=UTF-8' . "\r\n";
$headers .= 'From: Event Form<test#test.com>' . "\r\n";
$headers .= 'Cc: test#test.com, test#test.com' . "\r\n";
$body = '<html>
<head>
<title>Event</title>
<style>
h1 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
h3 {
font-family: "Century Gothic", CenturyGothic,
AppleGothic, sans-serif;
}
</style>
</head>
<body>
<h1>Event Details</h1>
<h3>Name: '.$name.'</h3>
<h3>Event Title: '.$eventtitle.'</h3>
<h3>Event Manager: '.$InCharge.'</h3>
<h3>Venue: '.$Venue.' - '.$ava.' Available</h3>
<h3>Date Start: '.$dates.'</h3>
<h3>Date End: '.$datee.'</h3>
<h3>Adults Attending: '.$adults.' Children Attending:
'.$children.'</h3>
<h3>Catering Requirements: '.$catreq.'</h3>
<h3>Logistic Requirements/Equipment: '.$logreq.'</h3>
<h3>IT Requirements: '.$itreq.'</h3>
<h3>Other Notes: '.$othern.'</h3>
<h3><font color="red">'.$tran.'</font>Transport Has Been
Booked</h3>
</body>
</html>' . "\r\n";
mail( $to, $subject, $body ,$headers );
/* echo "An Email Has Been Sent<br>Thank You."; */
header('Location: ./thanks.html');
}
}
The $to in mail function should be a string. If there are more than one email address then those should be comma separated. In your case you might need to do like following.
$to = $email . ','. implode(',', $email2);
Add email address with the comma
$email_to = "test#test.com,some#other.com,yet#another.net";
Also you can add
$headers = "Bcc: someone#domain.com";
Use a foreach on the array:
foreach($email2 as $to){
mail( $to, $subject, $body ,$headers );
}
Or like others are suggesting:
$to = $email.",".implode(",",$email2);
That doesn't make sense:
$to = $email;
$to = $email2;
Parmaeter $to should be a string of comma-seperated email-addresses, e.g.:
$to = $email1 . ", " . $email2 . ", " . $email3;
I added a cart function to this website, before It would only send one email after purchase because there was only one item at a time being purchased, now that I have added the cart function it needs to send one email instead of multiple emails.
This is the code I am using for processing the items purchased.
EDIT: Updated code
$item = array();
$size = array();
$color = array();
$price = array();
$querys = "SELECT * FROM ".$_SESSION["username"];
$ress = mysqli_query($connection, $querys);
if(mysqli_num_rows($ress) > 0){
while($rows = $ress->fetch_assoc()){
$bid = $rows["itemid"];
$description = $_POST["description"];
$bitem = $rows["itemname"];
$bsize = $rows["size"];
$bcolor = $rows["color"];
$bprice = $rows["price"];
$bcategory = $rows["category"];
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$company = $_POST["company"];
$address = $_POST["address"];
$suite = $_POST["suite"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$country = $_POST["country"];
$saddress = $_POST["saddress"];
$ssuite = $_POST["ssuite"];
$scity = $_POST["scity"];
$sstate = $_POST["state"];
$szip = $_POST["szip"];
$scountry = $_POST["scountry"];
$phone = $_POST["phone"];
$fax = $_POST["fax"];
$email = $_POST["email"];
$website = $_POST["website"];
$creditcard = $_POST["creditcard"];
$exdate = $_POST["experationdate"];
$cvv = $_POST["cvv"];
$create_date = date( 'Y-m-d H:i:s' );
$str_bitem = str_replace("'", "''", $bitem);
array_push($item, $bitem);
array_push($size, $bsize);
array_push($color, $bcolor);
array_push($price, $bprice);
$gw = new gwapi();
$gw->setLogin("demo", "password");
$gw->setBilling($firstname, $lastname, $company, $address, $suite, $city, $state, $zip, $country, $phone, $fax, $email, $website);
$gw->setShipping($firstname, $lastname, $company, $saddress, $ssuite, $scity, $sstate, $szip, $scountry, $email);
$gw->setOrder($bid, $description, 0, 0, 0, $_SERVER["REMOTE_ADDR"]);
$gw->doSale($bprice, $creditcard, $exdate, $cvv);
if($gw->responses['response'] == 1){
$firstname = $_SESSION["firstname"];
$lastname = $_SESSION["lastname"];
$query = "INSERT INTO orders (item_name, item_id, item_size, item_color, payer_email, first_name, last_name, address_name, address_city, address_state, address_zip, amount, country, create_date, shipped)
VALUES ('$str_bitem', '$bid', '$bsize', '$bcolor', '$email', '$firstname', '$lastname', '$saddress', '$scity', '$sstate', '$szip', '$bprice', '$scountry', '$create_date', 0)";
if(mysqli_query($db, $query)){
if($bsize=="N/A" && $bcolor=="N/A"){
define('DB_SERVER1', 'localhost');
define('DB_USERNAME1', 'grampmkn_gramsandpops');
define('DB_PASSWORD1', 'Grams123');
define('DB_DATABASE1', 'grampmkn_shop');
$db1 = mysqli_connect(DB_SERVER1,DB_USERNAME1,DB_PASSWORD1,DB_DATABASE1);
$sqlquery = "UPDATE `".$bcategory."` SET sold='1' WHERE id='$bid'";
if(mysqli_query($db1, $sqlquery)){
echo "Worked!";
}else{
echo "Error! : ";
echo mysqli_error($db1);
}
}else{
echo $bsize;
echo ":::::::";
echo $bcolor;
$conn = mysqli_connect('localhost', 'grampmkn_gramsandpops', 'Grams123', 'grampmkn_shop_quantity');
$query = "SELECT quantity FROM `".$bitem."` WHERE size='$bsize' AND color='$bcolor'";
$result = $conn->query ($query) or die($conn->error);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()){
$q = --$row["quantity"];
$query = "UPDATE `$bitem` SET quantity='$q' WHERE size='$bsize' AND color='$bcolor'";
if(mysqli_query($conn, $query)){
}else{
echo "TESTHING1";
echo mysqli_error($conn);
}
}
}else{
$query = "SELECT quantity FROM `".$bitem."` WHERE size='$bsize'";
$result = $conn->query ($query) or die($db->error);
while($row = $result->fetch_assoc()){
$q = --$row["quantity"];
$query = "UPDATE `$bitem` SET quantity='$q' WHERE size='$bsize'";
if(mysqli_query($conn, $query)){
}else{
echo "TESTING";
echo mysqli_error($conn);
}
}
}
}
}else{
echo mysqli_error($db);
echo " ::::: ";
echo mysqli_error($connection);
}
$masked = str_pad(substr($creditcard, -4), strlen($creditcard), '*', STR_PAD_LEFT);
$transid = $gw->responses['transactionid'];
$username = $_SESSION["username"];
$query = "DELETE FROM $username WHERE itemid='$bid'";
if(mysqli_query($connection, $query)){
echo "Worked";
}else{
echo "Error! ";
echo mysqli_error($connection);
}
$query = "show tables;";
$tres = $connection->query($query) or die($connection->error);
if($tres->num_rows > 0){
while($trow = $tres->fetch_assoc()){
$table = $trow["Tables_in_grampmkn_cart"];
$sql = "DELETE FROM `".$table."` WHERE category='$table' AND itemid='$bid'";
if(mysqli_query($connection, $sql)){
echo "Deleted items from others carts!";
}else{
echo "There were no similar items in others carts!";
echo $table." : ";
echo $tcategory." : ";
echo mysqli_error($connection);
}
}
}
}else{
?>
<div class="alert alert-warning">
<strong>Error!</strong> Your card was declined!
</div>
<?php
}
}
$itemlist = implode(', ', $item);
$sizelist = implode(', ', $size);
$colorlist = implode(', ', $color);
$pricelist = implode(', ', $price);
if(!empty($bcolor)){
$to = $email;
$subject = "Purchase Confirmation";
$txt = "Thank you for your purchase of <br> ".$sizelist." ".$itemlist." - ".$colorlist."<br>Price: ".$pricelist."<br>Transaction ID: ".$transid."<br>CC: ".$masked."<br> <img src='https://gramsandpops.com/images/Logo.png'>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: info#gramsandpops.com' . "\r\n" .
'Reply-To: info#gramsandpops.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to,$subject,$txt,$headers)){
}
}else{
$to = $email;
$subject = "Purchase Confirmation";
$txt = "Thank you for your purchase of <br> ".$sizelist." ".$itemlist."<br>Price: ".$pricelist."<br>Transaction ID: ".$transid."<br>CC: ".$masked."<br> <img src='https://gramsandpops.com/images/Logo.png'>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: info#gramsandpops.com' . "\r\n" .
'Reply-To: info#gramsandpops.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to,$subject,$txt,$headers)){
}
}
$to = "gramsandpopsblueridge#gmail.com";
$subject = "Purchase Order";
$txt = "Item: ".$itemlist."\n Size: ".$sizelist."\n Color: ".$colorlist."\n Price: ".$pricelist."\n Address: ".$saddress.
" ".$scity.", ".$sstate." ".$szip."\n Name: ".$firstname." ".$lastname."\n CC: ".$masked;
$headers = "From: admin#gramsandpops.com" . "\r\n" .
"CC: admin#gramsandpops.com";
if(mail($to,$subject,$txt,$headers)){
}
?>
<div class="alert alert-success">
<strong>Success!</strong> Your transaction was successfully processed! An email confirmation will be sent shortly.
</div>
<?php
}else{
echo mysqli_error($connection);
}
I had asked a question yesterday about sending an email every three days which was answered so I'm not sure if I should create a new one or add to the old.
The check is working fine as I get the correct ouptut on screen, but when I try to send the email it is only sending one result. I've tried foreach loops, putting the mail function in different places none of which seem to work. My code is below, I've removed most of the message parts as they are just long tables.
**UPDATE ****
I've added the recipients array into the while loop and also set $subject and $headers to empty values before adding values. This has worked.
$sql = "SELECT * FROM bookings " .
"WHERE DATE(date) > DATE(NOW()) " .
"AND dateofquote != '' " .
"AND email != '' " .
"AND confirmed = 0";
$result = mysql_query($sql);
$num_rows = mysql_numrows($result);
$today = date('Y-m-d');
if ($num_rows) {
while ($row = mysql_fetch_array($result)) {
$recipients = array(); // Updated
$id = $row['id'];
// rest of rows from db
$date_time1 = new DateTime($today);
$date_time2 = new DateTime($date_of_quote);
$interval = $date_time1->diff($date_time2);
$diff = $interval->format('%a');
if ($diff % 3 == 0) {
if ($type == 'W') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Weddding Email</h1>'.$message.'<br />End Wedding<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'D') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Debs Email</h1>'.$message.'<br />End Debs<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'CR') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Country Run Email</h1>'.$message.'<br />End Country Run<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'H') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Hourly Email</h1>'.$message.'<br />End Hourly<br /><br /><hr>';
// tried to send email from here for this option
}
} else {
echo 'something went wrong';
}
$recipients[] = $email;
$subject = ''; // Updated
$headers = ''; // Updated
$subject .= "An $type_value Enquiry has been received from company.ie";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Name <email#email.com>' . "\r\n";
foreach($recipients as $to){
if(mail($to, $subject, $message, $headers)) {
echo "E-Mail Sent to ";
echo $to.'<br />';
} else {
echo "There was a problem";
}
}
}
}
Try like this inside your while loop. Your mail content is inside the while loop, but you are trying mail function outside the while loop, so it is sending last content to all your mails in $recipients array.
$subject='';
$headers='';
$subject .= "An $type_value Enquiry has been received from company.ie";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Absolute Limos <email#email.com>' . "\r\n";
mail($email, $subject, $message, $headers);
your problem lies here:
$recipients[] = $email;
You create your email array outside your loop, thus you only get the last email address value.
Put it in your
while ($row = mysql_fetch_array($result)) {
I've been trying to add an email confirmation system to my website when people sign up and create an account but it will not add the key and the user id in the database. The other problem I'm running across is I'm trying to send a confirmation email but the email does not send. It echo's "message sent successfully" but when I check the email I put in, it is not received. Thanks in advance for your help! And yes, I am aware that mysql is prone to sql injection, but I would like to figure this out with mysql.
Here is my code:
EDIT: I replaced $insert_confirm with $hin and I renamed the table confirm to email_confirmation to maybe get rid of reserved words but I'm still getting an error
<?php
require_once '../scripts2/app_config.php';
require_once '../scripts2/database_connection.php';
$upload_dir = HOST_WWW_ROOT . "/uploads/profile_pics/";
$image_fieldname = "user_pic";
$first_name = trim($_REQUEST['first_name']);
$last_name = trim($_REQUEST['last_name']);
$name = $first_name . " " . $last_name;
$username = trim($_REQUEST['username']);
$password = trim($_REQUEST['password']);
$email = trim($_REQUEST['email']);
$bio = trim($_REQUEST['bio']);
if(isset($_POST['submit1'])) {
if($_POST['picture'] == 'picture1') {
$radio_value = "/home/users/web/b2620/ipg.knecktcom/testphp/uploads/profile_pics/1387503042-autopicture2.png";
} else if($_POST['picture'] == 'picture2') {
$radio_value = "/home/users/web/b2620/ipg.knecktcom/testphp/uploads/profile_pics/1387547040-auto_pic_grey2.png";
} else if($_POST['picture'] == 'picture3') {
$radio_value = "/home/users/web/b2620/ipg.knecktcom/testphp/uploads/profile_pics/1387503042-autopicture2.png";
} else {
$radio_value = "/home/users/web/b2620/ipg.knecktcom/testphp/uploads/profile_pics/1387503042-autopicture2.png";
}
}
$bgcolor = "#FF0000";
$check_email = "SELECT `email`" .
" FROM users" .
" WHERE `email` = '$email'";
$query_email = mysql_query($check_email);
$check_username = "SELECT `username`" .
" FROM users" .
" WHERE `username` = '$username'";
$query_username = mysql_query($check_username);
if(mysql_num_rows($query_email)>0 || mysql_num_rows($query_username)>0 ) {
if(mysql_num_rows($query_email)>0) {
$email_msg = "This email is already taken: {$email}";
header("Location:signup2.php?error_message={$email_msg}");
} else if(mysql_num_rows($query_username)>0) {
$username_msg = "This username is already taken: {$username}";
header("Location:signup2.php?error_message={$username_msg}");
} else {
$msg = "This email and username is already taken: {$email} , {$username}";
header("Location:signup2.php?error_message={$msg}");
}
} else {
$insert_sql = sprintf("INSERT INTO users " .
"(first_name, last_name, name, username, " .
"password, email, " .
"bio, " .
"user_pic_path, bgcolor) " .
"VALUES ('%s', '%s', '%s', '%s', '%s', '%s',
'%s', '%s', '%s');",
mysql_real_escape_string($first_name),
mysql_real_escape_string($last_name),
mysql_real_escape_string($name),
mysql_real_escape_string($username),
mysql_real_escape_string(crypt($password, $username)),
mysql_real_escape_string($email),
mysql_real_escape_string($bio),
mysql_real_escape_string($radio_value),
mysql_real_escape_string($bgcolor));
//insert the user into the database
$insert_user = mysql_query($insert_sql);
$private_user_id = mysql_insert_id();
function generateRandomString($length = 20) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
$private_user_key = generateRandomString();
$hin = sprintf("INSERT INTO email_confirmation " .
"(user_id, key) " .
"VALUES (%d, '%s');",
mysql_real_escape_string($private_user_id),
mysql_real_escape_string($private_user_key));
//insert the user into the database
mysql_query($hin);
echo mysql_error();
$name = mysql_real_escape_string($_POST['name']);
$create_user_table = mysql_query("CREATE TABLE `".$email."` ( friend_id INT, friend_status INT)");
if($insert_user && $create_user_table) {
// Email the new user the confirmation key
$to = $email;
$subject = 'Welcome!';
$message = "
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<p>Please click the following link to confirm your email:</p>
<p>Confirm Email</p>
</body>
</html>
";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Admin <email#email.com>' . "\r\n";
// Mail it
$retval = mail($to, $subject, $message, $headers);
if( $retval == true )
{
echo "Message sent successfully...";
echo "\n" . $to . "\n" . $message . "\n" . "\n" . $subject;
}
else
{
echo "Message could not be sent...";
}
}
//Redirect this user to the page that displays user information
// $msg = "Please check your email to confirm your email address";
// header("Location: newuser_signinA.php?error_message={$msg}");
// exit();
}
?>