unable to receive email through contact form here is my code - php

I am unable to receive email.here is my code.and i am trying to find my error but i am unable to find.so plzz anybody help me to solve this one.i am doubtful too about my code.here is my code which i have in my php file.my mail()
functions return true and i have modified my xamp config files.
<?php
require("connection.php");
?>
<?php
if(isset($_REQUEST))
{
$first = $_REQUEST['firstname'];
$middle = $_REQUEST['middlename'];
$last = $_REQUEST['lastname'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message =$_REQUEST['message'];
$query=" INSERT INTO `contact`(`id`,`first-name`, `middle-name`, `last-name`, `email`, `phone`, `message`) VALUES ('','$first','$middle','$last','$email','$phone','$message')";
$result = mysql_query($query);
if($result)
{
echo "data entered";
}
else
{
echo "data is not entered";
}
$to = "mehmood.asif31#gmail.com";
$subject = "Message From Contact Us Page";
$headers = "From:mehmood.asif31#gmail.com \r\n";
$headers .= "Bcc:mehmood.asif31#gmail.com \r\n";
$message = '<div style="margin:0 auto; padding:0px; width:800px">
<p style="font:bold 28px Arial, Helvetica, sans-serifl ; color:#006699; padding:0 0 0px 0; ">Feedback Message</p>
<div style=" margin:0 0 20px 0; font-family:Arial, Helvetica, sans-serif; font-size:15px; padding:10px; margin:0px; line-height:22px;">
<table>
<tr>
<td><strong>Name:</strong></td>
<td>'.$first.'</td>
</tr>
<tr>
<td><strong>Email ID:</strong></td>
<td>'.$email.'</td>
</tr>
<tr>
<td><strong>Phone No:</strong></td>
<td>'.$phone.'</td>
</tr>
<tr>
<td><strong>Message:</strong></td>
<td>'.$message.'</td>
</tr>
</table>
</div>
</div>';
//echo $message; exit;
mail($to, $subject, $message, $headers);
unset($_POST);
}
?>

Related

Unknown column 'activation_code' in 'field list'

I have a problem with my website of a game called World of Warcraft. In the registration part when I want to register, I skip this error
Unknown column 'activation_code' in 'field list'
I created the account, I can enter the page, but at the time of entering the game it tells me that my account is blocked
Unknown column 'activation_code' in 'field list'
Here is my file Register.php... help me please
> <?php
require_once("".$_SERVER['DOCUMENT_ROOT']."/header.php");
/*generate the code for activate the acccount*/
function random_str($length, $keyspace = '_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$keyspace = str_shuffle($keyspace );
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces []= $keyspace[random_int(0, $max)];
}
return implode('', $pieces);
}
$regcode = random_str(255);
/*
$a = random_str(32);
$b = random_str(8, 'abcdefghijklmnopqrstuvwxyz');
*/
/*END genetare code*/
function encryptpw($user, $pass) {
$user = strtoupper($user);
$pass = strtoupper($user);
return sha1($user.':'.$pass);
}
//store all results from query records
$results = array();
$accexist = 'SELECT * FROM battlenet_accounts WHERE email = "'.$_POST['email'].'"';
//SQL select query
$accexistresult = mysqli_query($dbh, $accexist)or die(mysqli_error($dbh));
//execute SQL statement
$accexistrows = mysqli_num_rows($accexistresult);
// get number of rows returned
if($accexistrows){
while($row = mysqli_fetch_array($accexistresult)){
$results["accexist"] = $row;
}
}
$emailexist = $results["accexist"]["email"];
if(isset($_POST['submit']) AND $emailexist == ""){
$email = strtoupper($_POST['email']);
$expansion = "7";
$bnetindex = "1";
$acclock = "1";
$accunlock = "0";
// Battlenet Password
$bnetpassword = strtoupper(bin2hex(strrev(hex2bin(strtoupper(hash("sha256",strtoupper(hash("sha256", strtoupper($email)).":".strtoupper($_POST['pass']))))))));
// Queries
if($insbnet = 'INSERT INTO battlenet_accounts (email, sha_pass_hash, locked) VALUES ("'.$email.'", "'.$bnetpassword.'", "'.$acclock.'");'){
$insbnetresult = mysqli_query($dbh, $insbnet);
$getaccid = 'SELECT * FROM battlenet_accounts WHERE email = "'.$email.'"';
//SQL select query
$getaccidresult = mysqli_query($dbh, $getaccid)or die(mysqli_error($dbh));
//execute SQL statement
$getaccidrows = mysqli_num_rows($getaccidresult);
// get number of rows returned
if($getaccidrows){
while($row = mysqli_fetch_array($getaccidresult)){
$results["id"] = $row;
}
}
$id = $results["id"]["id"];
$bnetacc = $id;
$username = $bnetacc."#".$bnetindex;
$accpassword = encryptpw($username, $_POST['pass']);
if($insacc = 'INSERT INTO account (username, sha_pass_hash, email, expansion, battlenet_account, battlenet_index, activation_code) VALUES ("'.$username.'", "'.$accpassword.'", "'.$email.'", "'.$expansion.'", "'.$bnetacc.'", "'.$bnetindex.'", "'.$regcode.'")'){
$insaccresult = mysqli_query($dbh, $insacc) or die(mysqli_error($dbh));
//execute SQL statement
$results = array();
$success = '<h3 style="color: green;" align="center">Your Account: <span style="color: white;">' . strtolower($email) . '</span>
was created successfully! An email was sent to you with informations on how to activate it.</h3>';
//start the mail() setup
$password = $_POST['pass'];
$youremail = 'noreply#shadowmelt.com';
$subject = 'ShadowMelt Register Confirm';
$message = '<html><head>';
$message .= '</head><body>';
$message .= '<p align="left">Greetings,</p>';
$message .= '<p align="left">You are receiving this email because you register on our Website platform with this email <b>( ' . strtolower($email) . ' )</b>. If you not did this action, please delete this message.</p>';
$message .= '<p align="left">Next, it follows the data for you to Login in-game, however you need to activate your account to be able to play. To activate your Account, please click on next link or copy paste on your browser:</p>';
$message .= '<p align="center"><a style="
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf));
background:-moz-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-webkit-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-o-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-ms-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:linear-gradient(to bottom, #ededed 5%, #dfdfdf 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ededed\', endColorstr=\'#dfdfdf\',GradientType=0);
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
cursor:pointer;
color:#777777;
font-family:Arial;
font-size:15px;
font-weight:bold;
padding:13px 24px;
text-decoration:none;
text-shadow:0px 1px 0px #ffffff;
" href="https://www.shadowmelt.com/register?confreg=' . $regcode . '">Activate Account</a></p>';
$message .= '<p align="left"><b>Login:</b> ' . strtolower($email) . ' <br /><b>Password:</b> ' . $password . '</p>';
$message .= '<p align="left">For more information, how to connect, visit us on our website!</p>';
$message .= '</body></html>';
$headers = 'From: ' . $youremail . "\r\n";
$headers .= 'MIME-Version: 1.0' ."\r\n";
$headers .= 'Content-Type: text/HTML; charset=utf-8' . "\r\n";
$sendto = $email;
mail($sendto, $subject, $message, $headers);
}else{
echo "Insert account error...";
}
}else{
echo "Insert baccount error...";
}
}elseif(isset($_POST['submit']) AND $emailexist != ""){
$accexisterror = '<h3 style="color: red;" align="center">Your Account was not Created! That email <span style="color: white;">'.strtolower($email).'</span> already exists.</h3>';
}
?>
<div class="content">
<div class="container row">
<div id="left-content">
<div class="post_wrap">
<div class="news">
<br>
<br>
<br>
<!-- Main -->
<?php
if(isset($_GET["confreg"]) != ""){
$acclock = "1";
$accunlock = "0";
$confreg = htmlspecialchars($_GET["confreg"]);
$getaccemail = 'SELECT * FROM account WHERE activation_code = "'.$confreg.'"';
//SQL select query
$accemailresult = mysqli_query($dbh,$getaccemail) or die(mysqli_error($dbh));
//execute SQL statement
$accemailrows = mysqli_num_rows($accemailresult);
// get number of rows returned
if($accemailrows){
while($row = mysqli_fetch_array($accemailresult)){
$results["email"] = $row;
}
}
$idaccemail = $results["email"]["email"];
$getacccode = 'SELECT * FROM account WHERE email = "'.$idaccemail.'"';
//SQL select query
$acccoderesult = mysqli_query($dbh,$getacccode);
//execute SQL statement
$acccoderows = mysqli_num_rows($acccoderesult);
// get number of rows returned
if($acccoderows){
while($row = mysqli_fetch_array($acccoderesult)){
$results["storedcode"] = $row;
}
}
$storedcode = $results["storedcode"]["activation_code"];
$getacclock = 'SELECT * FROM battlenet_accounts WHERE email = "'.$idaccemail.'"';
//SQL select query
$acclockresult = mysqli_query($dbh,$getacclock);
//execute SQL statement
$acclockrows = mysqli_num_rows($acclockresult);
// get number of rows returned
if($acclockrows){
while($row = mysqli_fetch_array($acclockresult)){
$results["storedlock"] = $row;
}
}
$storedlock = $results["storedlock"]["locked"];
if(isset($confreg) == $storedcode AND $storedlock == $acclock){
$activacc = 'UPDATE battlenet_accounts SET locked = "'.$accunlock.'" WHERE email = "'.$idaccemail.'"';
//SQL select query
$activaccresult = mysqli_query($dbh,$activacc);
//execute SQL statement
if($activaccresult){
echo '<h3 style="color: green;" align="center">Your Account: <span style="color: white;">' . strtolower($idaccemail) . '
</span> was Activated! How to Connect?</h3>';
}else{
echo '<h3 align="center"><span style="color: red;">Your Account: </span><span style="color: white;">' . strtolower($idaccemail) . '
</span> was Not Activated. Something went wrong, please verify if you copy the correct full link, and if you continue receiving
this error message, please contact us!</h3>';
echo '<script type="text/javascript">alert(" Something went wrong, please verify if you copy the correct full link, and if you continue receiving
this error message, please contact us!");</script>';
}
}elseif(isset($confreg) == $storedcode AND $storedlock == $accunlock){
echo '<h3 align="center"><b>(i)</b> <i style="color: yellow;">Your account has already been activated.</i></h3>';
echo '<script type="text/javascript">alert("Your account has already been activated.");</script>';
}elseif(isset($confreg) != $storedcode){
echo '<h3 align="center"><b>(i)</b> <i style="color: yellow;">We can not identify this link!</i></h3>';
echo '<script type="text/javascript">alert("We can not identify this link!");</script>';
}else{
echo '<script type="text/javascript">alert("Something was wrong! We do not identify the issue, please contact us.");</script>';
}
}elseif(isset($success)){
echo $success;
}elseif(isset($accexisterror)){
echo $accexisterror;
}else{
?>
<h3 style="font-size:20px;font-weight:bold;text-transform:uppercase;" align="center">Sign-Up for Shadowmelt!</h3>
<hr />
<br />
<br />
<br />
<div style="width: 630px; margin-left: auto; margin-right: auto;"><form style="display: inline;" target="_blank" action=""><input type="hidden" name="shadowmelt" value="1" /><button class="upmenu">ShadowMelt [Legion]</button></form>
<form style="display: inline; margin-left: 20px;" target="_blank" action="http://www.rainandthunder.net/#register"><button class="upmenu">RainAndThunder [Vanilla]</button></form></div>
<br />
<br />
<br />
<hr />
<form action="" method="post" name="reg">
<table style="border-spacing: 30px; border-collapse: separate;" class="form">
<tr>
<td align="right">
E-mail Address:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="email" type="email" maxlength="254" placeholder="Please insert a valid email(1)" required />
</td>
</tr>
<tr>
<td align="right">
Password:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="pass" type="password" maxlength="16" placeholder="Insert a password to use on login" required />
</td>
</tr>
<tr>
<td align="right">
Confirm password:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="pass2" type="password" maxlength="16" placeholder="Insert again your password" required />
</td>
</tr>
<tr>
<td></td>
<td align="center">
<input type="submit" class="sbm" value="Register" name='submit' />
</td>
</tr>
</table>
</form>
<p align="center"><b>¹</b> <i style="color: yellow;">Is required use a valid email, to activate your Account,
since our system will send you an email with details on how to activate your Account.</i></p>
<?php } ?>
</div>
</div>
</div>
<div id="right-content">
<br>
<img src="images/box.png">
</div>
</div>
</div>
<?php include_once("".$_SERVER['DOCUMENT_ROOT']."/footer.php"); ?>
You just have to add this not existing column:
ALTER TABLE account
ADD activation_code char(64);
either this table column is still missing or you have just spelled it wrong, if necessary check that before you create a new column for nothing

Can't send checklist to email from html

I need to do a simple script with two parts. First one is sending just name, phone number etc. and works perfectly already:
But after it i need to send a checklist to the same email, but still is nothing there.
My html:
<form action="contact.php" method="post" id="form" class="contact-form">
<table style="color: DEB441; font-size: 19px; margin-left: 60px; margin-top: 40px; float: left;">
<tr>
<td><font color="FFFFFF">Imie:</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_imie" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">Nazwisko:</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_nazwisko" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">Adres:</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_adres" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">Telefon</td>
<td style="padding:0px">
<textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_telefon" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td><font color="FFFFFF">E-mail:</td>
<td style="padding:0px">
<textarea style="outline-color: FFFFFF; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_email" rows="2" cols="20"></textarea>
</td>
</tr>
<tr>
<td style="width: 150px;">
<p style="align: left; margin-top: 2px; margin-right: 10px;"><br>
<font style="font-size: 16px;" color="#FFFFFF" align="left">
Wybierz produkty:<br><br>
<font style="font-size: 12px;" color="#FFFFFF" align="left">
Herbatniki w pudelkach <br>
<hr align="left" width="110px"><bt>
<input type="checkbox" name="thenderese" value="thenderese" />Thenderese<br>
<input type="checkbox" name="petipa" value="petipa" />Petipa<br>
<input type="checkbox" name="biscripts" value="biscripts" />Biscripts<br>
</p>
</td>
<td style="width: 150px;">
<p style="width: 250px; align: left;"><br>
<font style="font-size: 12px;" color="#FFFFFF" align="left">
Herbatniki Pakowane pojedynczo<br>
<hr align="left" width="160px">
<input type="checkbox" name="6g" value="g6g" />6g
<input type="checkbox" name="150g" value="g150g" />150g
<input type="checkbox" name="300g" value="g300g" />300g
</p>
</td>
</tr>
<tr>
<td style="width: 200px; margin-right: 250px;">
<p align="left" style="align: left; margin-top:0px;"><br>
<font style="font-size: 12px;" color="#FFFFFF" align="left">
Inne
<hr align="left" width="150px">
<input type="checkbox" name="folia" value="folia">Biscripts opakowane w folie<br>
<input type="checkbox" name="speculoos1" value="speculoos1" />1,5 kg (proszek speculoos)<br>
<input type="checkbox" name="speculoos2" value="speculoos2" />1,1 kg (pokruszony speculoos)<br>
<input type="checkbox" name="krem" value="krem biscripts" />krem biscripts<br>
</p>
</td>
</tr>
</table>
</form>
and my PHP
<?php
$field_imie = $_POST['cf_imie'];
$field_nazwisko = $_POST['cf_nazwisko'];
$field_adres = $_POST['cf_adres'];
$field_telefon = $_POST['cf_telefon'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'serwis#reskomp.pl';
$subject = 'nowe zamowienie '.$field_imie;
$body_message = 'Od: '.$field_imie."\n";
$body_message .= 'Nazwisko: '.$field_nazwisko."\n";
$body_message .= 'Adres: '.$field_adres."\n";
$body_message .= 'Telefon: '.$field_telefon."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Szczegoly zamowienia: '.$field_message;
$thenderese = $_POST['thenderese'];
if ($thenderese != 'Yes') {
$thenderese = 'No';
}
$petipa = $_POST['petipa'];
if ($petipa != 'Yes') {
$petipa = 'No';
}
$biscripts = $_POST['biscripts'];
if ($biscripts != 'Yes') {
$biscripts = 'No';
}
$g6g = $_POST['6g'];
if ($g6g != 'Yes') {
$g6g = 'No';
}
$g150g = $_POST['150g'];
if ($g150g != 'Yes') {
$g150g = 'No';
}
$g300g = $_POST['300g'];
if ($g300g != 'Yes') {
$g300g = 'No';
}
$folia = $_POST['folia'];
if ($folia != 'Yes') {
$folia = 'No';
}
$speculoos1 = $_POST['speculoos1'];
if ($speculoos1 != 'Yes') {
$speculoos1 = 'No';
}
$speculoos2 = $_POST['speculoos2'];
if ($speculoos2 != 'Yes') {
$speculoos2 = 'No';
}
$krem = $_POST['krem'];
if ($krem != 'Yes') {
$krem = 'No';
}
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Zamowienie zostalo przyjete do realizacji.');
window.location = '../herbatniki/index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Blad wysylania wiadomosci. Prosimy o kontakt na adres: coo.maan#gmail.com');
window.location = 'Contacts.html';
</script>
<?php
}
?>
If somebody could help me...
I know that i should use more css, but this is not the reason.
It looks like you have no way to submit your form.
Further, to add your checkbox data to your email message, you can use something like the following.
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
var_dump($_POST);
$message = '';
$message .= sprintf("Name: %s\n", isset($_POST['name']) ? $_POST['name'] : '');
$message .= sprintf("Foo wanted: %s\n", isset($_POST['foo']) ? 'Yes' : 'No');
$message .= sprintf("Bar wanted: %s\n", isset($_POST['bar']) ? 'Yes' : 'No');
var_dump($message);
}
?>
<form method="POST">
Your Name:<input type="text" name="name" /><br />
<input type="checkbox" name="foo" />You want Foo?<br />
<input type="checkbox" name="bar" />You want Bar?<br />
<input type="submit">
</form>
However please research 'email injection in php'.
You need to add the content to $body_message.
Change
$thenderese = $_POST['thenderese'];
if ($thenderese != 'Yes') {
$thenderese = 'No';
}
to
$thenderese = $_POST['thenderese'];
$body_message .= 'thenderese';
if ($thenderese != 'Yes') {
$body_message .= 'No';
}
else {
$body_message .= 'Yes';
}
$body_message .= '/n';
and continue for the rest of your if statements.

How to add html table to database and save

I am new to PHP.I had created the table with the button "save Form".I am unable to save the table data to database.When I click on the "save form" button no action is performing.Please help me.
This is my Form.phtml
<div>
<b> Hello <?php echo $_POST["name"]; ?>!</b><br>
<b>Email :</b> <?php echo $_POST["email"]; ?>.<br>
<b>Gender :</b> <?php echo $_POST["gender"]; ?>.<br>
<b>Birthday :</b>
<?php
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$date = $day."-".$month."-".$year;
$myDate = date("d F Y", strtotime($date));
echo $myDate;
?>
</div>
<form action="sendmail.php" method="post" id="vaccination-form">
<div>
<table border="1" style="width:100%">
<tr>
<th id= "sno" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class="bg-color" width="5%">S.No</th>
<th id= "vaccine" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class="bg-color center" width="32%">Vaccine</th>
<th id="decsription" style="font-family: sans-serif; font-size: 100%; font-weight: bold;">Description</th>
<th id="duedate" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class ="bg-color" width="15%">Due Date</th>
</tr>
<tr>
<td>1</td>
<tr>
</table>
</form>
<div>
<button type="submit" name="submit" style="margin-top: 1cm;"title="<?php echo $this->__('Save Form') ?>" value="submit "class="button"><span><span><?php echo $this->__('Save Form')?></span> </span> </button>
</div>
sendmail.php
<?php
//due dates
$myDate=$_POST['myDate'];
$dueDate=$_POST['dueDate'];
$rodueDate=$_POST['rodueDate'];
$didueDate=$_POST['didueDate'];
$pdueDate=$_POST['pdueDate'];
$hadueDate=$_POST['hadueDate'];
$indueDate=$_POST['indueDate'];
$idueDate=$_POST['idueDate'];
$rdueDate=$_POST['rdueDate'];
$vdueDate=$_POST['vdueDate'];
$tdueDate=$_POST['tdueDate'];
$hdueDate=$_POST['hdueDate'];
$mdueDate=$_POST['mdueDate'];
$email=$_POST['email'];
$name=$_POST['name'];
$to=$email;
$subject= "Vaccination Schedule For ".$name;
$message=
'
</table>';
// 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";
$headers.= "From: someone#example.com" . "\r\n" ;
if( mail($to, $subject, $message, $headers))
{
echo 'Your mail has been sent successfully';
}
else
{
echo 'Unable to send email. Please try again.';
}
?>
Show us your sendmail.php.
Mainly you need to get POST variables into sendmail.php and then create a insert sql statement with data you got from POST variables..
How to do stuff above is totaly up to you, there are many ways, but we cannot tell you since you didnt give us enough info about your system.
I do not think the right thing to do , but still think you need to put the submit button between tags

I am getting some double database entries from the from my form submission

I have an online application That is working but I am getting some double database entries. Not every submission creates a double entry but many are. If anyone sees the reason in my code and can tell me It would be appreciated:
<?php
#$upload_Name = $_FILES['Resume']['name'];
#$upload_Size = $_FILES['Resume']['size'];
#$upload_Temp = $_FILES['Resume']['tmp_name'];
#$upload_Mime_Type = $_FILES['Resume']['type'];
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
// Validation
// check only if file
if( $upload_Size > 0)
{
if( $upload_Size == 0)
{
header("Location: error.html");
}
if( $upload_Size >200000)
{
//delete file
unlink($upload_Temp);
header("Location: error.html");
}
if( $upload_Mime_Type != "application/msword" AND $upload_Mime_Type != "application/pdf" AND $upload_Mime_Type != "application/vnd.openxmlformats- officedocument.wordprocessingml.document")
{
unlink($upload_Temp);
header("Location: error.html");
}
}//end wrapper of no file
// Where the file is going to be placed
$target_path = “../../XXXX/uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['Resume']['name']);
if(move_uploaded_file($_FILES['Resume']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['Resume']['name']).
" has been uploaded";
} else{
echo "";
}
?><?php
if(isset($_POST['email'])) {
require_once 'Mail.php'; // PEAR Mail package
require_once 'Mail/mime.php';
$email_to = “name#yoursite.com”; //Enter the email you want to send the form to
$email_subject = "Employment Application"; // You can put whatever subject here
$host = "mail.yourdomain.com"; // The name of your mail server. (Commonly mail.yourdomain.com if your mail is hosted with xxx)
$username = "yoursite.com"; // A valid email address you have setup
$from_address = "name#yoursite.com"; // If your mail is hosted with Site this has to match the email address above
$password = “XXX”; // Password for the above email address
$reply_to = “XXX#yoursite.com"; //Enter the email you want customers to reply to
$port = "50"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with Site
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// Validate expected data exists
if(!isset($_POST['Position_Applying']) || !isset($_POST['Position_type']) || !isset($_POST['First_name']) || !isset($_POST['Last_name']) || !isset($_POST['Street']) || !isset($_POST['City']) || !isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_ServerTime = $_POST['hdw_ServerTime'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$Middle_name = $_POST['Middle_name'];
$Last_name = $_POST['Last_name'];
$Street = $_POST['Street'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$One_Phone = $_POST['One_Phone'];
$crlf = "n";
// required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$First_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Employment Application Details Below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Position Applying: ".clean_string($Position_Applying)."\n";
$email_message .= "Position Type: ".clean_string($Position_type)."\n";
$email_message .= "\n";
$email_message .= "First name: ".clean_string($First_name)."\n";
$email_message .= "Last Name: ".clean_string($Last_name)."\n";
$email_message .= "\n";
$email_message .= "Street: ".clean_string($Street)."\n";
$email_message .= "City: ".clean_string($City)."\n";
$email_message .= "State: ".clean_string($State)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($One_Phone)."\n";
$email_message .= "\n";
$email_message .= "Referred By: ".clean_string($Referred_by )."\n";
$email_message .= "Older than 18: ".clean_string($eighteen )."\n";
$email_message .= "US Citizen: ".clean_string($US_citizen)."\n";
$email_message .= "Crime Conviction: ".clean_string($Crime_convict)."\n";
$email_message .= "NYS Professional License: ".clean_string($NYS_professional_lic)."\n";
$email_message .= "Other License: ".clean_string($Other_professional_lic)."\n";
$email_message .= "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($Resume,'application/pdf');
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email_to, $headers, $email_message);
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email, $headers, $email_message);
if (PEAR::isError($mail)) {?>
<!-- include your own failure message html here -->
Unfortunately, the message could not be sent at this time. Please try again later.
<!-- Uncomment the line below to see errors with sending the message -->
<!-- <?php echo("<p>". $mail->getMessage()."</p>"); ?> -->
<?php } else { ?>
<!-- include your own success message html here -->
<?php } } ?>
<style type="text/css">
<!--
.style2 {font-size: 14px}
.style3 { font-size: 14px;
font-family: Verdana;
}
-->
</style>
<link href=“XXXDatabaseB/js.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(XXXDatabaseB/images/green100px.jpg);
background-color: #FFF09F;
}
.style4 {color: #A20246}
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
font-weight: bold;
padding: 10px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FFF09F;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
.style5 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
color: #FFFFFF;
}
.style6 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (xxx_square_slice.psd) -->
<table width="830" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" id="Table_01">
<tr valign="top">
<td height="258" colspan="2"><?php include 'header.php'; ?></td>
</tr>
<tr>
<td width="100%" valign="top">
<?php
$host = “xxxxx.net";
$username = “xxxxx”;
$password = “xxxxx”;
$dbname = “xxxxxx”;
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$sql = "INSERT INTO `new_app`(`hdw_id`, `hdw_Country`, `hdw_IP`, `hdw_Referer`, `hdw_ServerTime`, `hdw_Browser`, `hdw_UserAgent`, `Position_Applying`, `Position_one`, `Position_two`, `Position_three`, `Position_type`, `Shift_type`, `First_name`)
VALUES ('$hdw_id', '$hdw_Country', '$hdw_IP', '$hdw_Referer', CURRENT_TIMESTAMP, '$hdw_Browser', '$hdw_UserAgent', '$Position_Applying', '$Position_one', '$Position_two', '$Position_three', '$Position_type', '$Shift_type', '$First_name')";
$result=mysql_query($sql);
if($result){
echo "";
}
else {
echo "ERROR";
}
mysql_close();
?>
<table width="100%" height="508" border="0" align="left" cellpadding="20" cellspacing="5">
<tbody>
<tr>
<td colspan="2" valign="middle">
<h2>Thank you for your Application!</h2>
</p>
</td></tr></tbody></table></td>
</tr>
<tr>
<td colspan="2" valign="top"><?php include 'footer.php'; ?></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
The code looks ok to me the insert is not executed twice and is no where near a loop of any kind. So it makes me wonder that maybe its user error. I would look at how the file upload section seems to allow the rest of the code to run even if it fails. If it fails the user will change something with the file and resubmit. This happens because you need to exit; after your headers.
I also like to end my insert statements with a LIMIT 1 just because it is limited to one - but I doubt that the problem.
I have made the changes I suggested in the code below:
<?php
#$upload_Name = $_FILES['Resume']['name'];
#$upload_Size = $_FILES['Resume']['size'];
#$upload_Temp = $_FILES['Resume']['tmp_name'];
#$upload_Mime_Type = $_FILES['Resume']['type'];
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
// Validation
// check only if file
if( $upload_Size > 0)
{
if( $upload_Size == 0)
{
header("Location: error.html");
exit;
}
if( $upload_Size >200000)
{
//delete file
unlink($upload_Temp);
header("Location: error.html");
exit;
}
if( $upload_Mime_Type != "application/msword" AND $upload_Mime_Type != "application/pdf" AND $upload_Mime_Type != "application/vnd.openxmlformats- officedocument.wordprocessingml.document")
{
unlink($upload_Temp);
header("Location: error.html");
exit;
}
}//end wrapper of no file
// Where the file is going to be placed
$target_path = “../../XXXX/uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['Resume']['name']);
if(move_uploaded_file($_FILES['Resume']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['Resume']['name']).
" has been uploaded";
} else{
echo "";
}
?><?php
if(isset($_POST['email'])) {
require_once 'Mail.php'; // PEAR Mail package
require_once 'Mail/mime.php';
$email_to = “name#yoursite.com”; //Enter the email you want to send the form to
$email_subject = "Employment Application"; // You can put whatever subject here
$host = "mail.yourdomain.com"; // The name of your mail server. (Commonly mail.yourdomain.com if your mail is hosted with xxx)
$username = "yoursite.com"; // A valid email address you have setup
$from_address = "name#yoursite.com"; // If your mail is hosted with Site this has to match the email address above
$password = “XXX”; // Password for the above email address
$reply_to = “XXX#yoursite.com"; //Enter the email you want customers to reply to
$port = "50"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with Site
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// Validate expected data exists
if(!isset($_POST['Position_Applying']) || !isset($_POST['Position_type']) || !isset($_POST['First_name']) || !isset($_POST['Last_name']) || !isset($_POST['Street']) || !isset($_POST['City']) || !isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_ServerTime = $_POST['hdw_ServerTime'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$Middle_name = $_POST['Middle_name'];
$Last_name = $_POST['Last_name'];
$Street = $_POST['Street'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$One_Phone = $_POST['One_Phone'];
$crlf = "n";
// required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$First_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Employment Application Details Below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Position Applying: ".clean_string($Position_Applying)."\n";
$email_message .= "Position Type: ".clean_string($Position_type)."\n";
$email_message .= "\n";
$email_message .= "First name: ".clean_string($First_name)."\n";
$email_message .= "Last Name: ".clean_string($Last_name)."\n";
$email_message .= "\n";
$email_message .= "Street: ".clean_string($Street)."\n";
$email_message .= "City: ".clean_string($City)."\n";
$email_message .= "State: ".clean_string($State)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($One_Phone)."\n";
$email_message .= "\n";
$email_message .= "Referred By: ".clean_string($Referred_by )."\n";
$email_message .= "Older than 18: ".clean_string($eighteen )."\n";
$email_message .= "US Citizen: ".clean_string($US_citizen)."\n";
$email_message .= "Crime Conviction: ".clean_string($Crime_convict)."\n";
$email_message .= "NYS Professional License: ".clean_string($NYS_professional_lic)."\n";
$email_message .= "Other License: ".clean_string($Other_professional_lic)."\n";
$email_message .= "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($Resume,'application/pdf');
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email_to, $headers, $email_message);
// This section creates the email headers
$auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password);
$headers = array('From' => $from_address, 'To' => $email, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
// This section send the email
$smtp = Mail::factory('smtp', $auth);
$mail = $smtp->send($email, $headers, $email_message);
if (PEAR::isError($mail)) {?>
<!-- include your own failure message html here -->
Unfortunately, the message could not be sent at this time. Please try again later.
<!-- Uncomment the line below to see errors with sending the message -->
<!-- <?php echo("<p>". $mail->getMessage()."</p>"); ?> -->
<?php } else { ?>
<!-- include your own success message html here -->
<?php } } ?>
<style type="text/css">
<!--
.style2 {font-size: 14px}
.style3 { font-size: 14px;
font-family: Verdana;
}
-->
</style>
<link href=“XXXDatabaseB/js.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(XXXDatabaseB/images/green100px.jpg);
background-color: #FFF09F;
}
.style4 {color: #A20246}
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
font-weight: bold;
padding: 10px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FFF09F;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
.style5 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
color: #FFFFFF;
}
.style6 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (xxx_square_slice.psd) -->
<table width="830" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" id="Table_01">
<tr valign="top">
<td height="258" colspan="2"><?php include 'header.php'; ?></td>
</tr>
<tr>
<td width="100%" valign="top">
<?php
$host = “xxxxx.net";
$username = “xxxxx”;
$password = “xxxxx”;
$dbname = “xxxxxx”;
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
$hdw_id = $_POST['hdw_id'];
$hdw_Country = $_POST['hdw_Country'];
$hdw_IP = $_POST['hdw_IP'];
$hdw_Referer = $_POST['hdw_Referer'];
$hdw_Browser = $_POST['hdw_Browser'];
$hdw_UserAgent = $_POST['hdw_UserAgent'];
$Position_Applying = $_POST['Position_Applying'];
$Position_one = $_POST['Position_one'];
$Position_two = $_POST['Position_two'];
$Position_three = $_POST['Position_three'];
$Position_type = $_POST['Position_type'];
$Shift_type = $_POST['Shift_type'];
$First_name =$_POST['First_name'];
$sql = "INSERT INTO `new_app`(`hdw_id`, `hdw_Country`, `hdw_IP`, `hdw_Referer`, `hdw_ServerTime`, `hdw_Browser`, `hdw_UserAgent`, `Position_Applying`, `Position_one`, `Position_two`, `Position_three`, `Position_type`, `Shift_type`, `First_name`)
VALUES ('$hdw_id', '$hdw_Country', '$hdw_IP', '$hdw_Referer', CURRENT_TIMESTAMP, '$hdw_Browser', '$hdw_UserAgent', '$Position_Applying', '$Position_one', '$Position_two', '$Position_three', '$Position_type', '$Shift_type', '$First_name') LIMIT 1";
$result=mysql_query($sql);
if($result){
echo "";
}
else {
echo "ERROR";
}
mysql_close();
?>
<table width="100%" height="508" border="0" align="left" cellpadding="20" cellspacing="5">
<tbody>
<tr>
<td colspan="2" valign="middle">
<h2>Thank you for your Application!</h2>
</p>
</td></tr></tbody></table></td>
</tr>
<tr>
<td colspan="2" valign="top"><?php include 'footer.php'; ?></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>

How to embed HTML with PHP array in e-mail message?

I am trying to send an email whith the order details after visitor submit the order. I am trying to embed my order array result in a html tag but it is not working. Help please
senmail.php
<?php
$to = "member#yahoo.com";
$from = "sales#thesite.com";
$headers = "From: $from";
$subject = "Custom computer Order Confirmation Nunber_ $orderid";
$message = "
<html>
<body>
<p> This doesn't render well</p>
<table style="margin-left:50px; text-align:left;">
<tr>
<th style="width:20%; border-bottom:solid 1px #000;">Item ID</th>
<th style="width:40%; border-bottom:solid 1px #000">Description</th>
<th style="width:15%; border-bottom:solid 1px #000">Quantity</th>
<th style="width:20%; border-bottom:solid 1px #000">Unit Price</th>
</tr>
<?php
foreach($_SESSION["cart_array"]as $item):
$item_id=$item['part_id'];
$sql = mysqli_query($con,"SELECT * FROM product_description
WHERE product_id='$item_id' LIMIT 1");
While($row=mysqli_fetch_array($sql)){
$product_name=$row["name"];
}
?>
<tr>
<td><?php echo $item['part_id'] ?></td>
<td><?php echo $product_name ?></td>
<td><?php echo $item['quantity'] ?></td>
<td><?php echo $item['price'] ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
";
$mailsent = mail($to, $subject, $message, $headers);
.........
?>
bored enough to fix it all for you:
<?php
$to = "member#yahoo.com";
$from = "sales#thesite.com";
$headers = "From: $from";
$subject = "Custom computer Order Confirmation Nunber_ $orderid";
$message = '
<html>
<body>
<p> This doesn\'t render well</p>
<table style="margin-left:50px; text-align:left;">
<tr>
<th style="width:20%; border-bottom:solid 1px #000;">Item ID</th>
<th style="width:40%; border-bottom:solid 1px #000">Description</th>
<th style="width:15%; border-bottom:solid 1px #000">Quantity</th>
<th style="width:20%; border-bottom:solid 1px #000">Unit Price</th>
</tr>';
foreach($_SESSION["cart_array"] as $item){
$item_id = $item['part_id'];
$sql = mysqli_query($con,"SELECT * FROM product_description
WHERE product_id='$item_id' LIMIT 1");
While ( $row = mysqli_fetch_array($sql) ){
$product_name = $row["name"];
}
$message .= '
<tr>
<td>'.$item['part_id'].'</td>
<td>'.$product_name.'</td>
<td>'.$item['quantity'].'</td>
<td>'.$item['price'].'</td>
</tr>';
}
$message .= ' </table>
</body>
</html>';
$mailsent = mail($to,$subject,$message,$headers);
//.........
?>
i only fixed the basics, this is still far from ideal
You cannot embed PHP code inside strings and magically have it execute.
The correct approach would be to store the message in a string and use a processing loop to add to it. Such a result would look like:
$msg = "Beginning of message\n";
foreach($_SESSION["cart_array"]as $item) {
$item_id=$item['part_id'];
$sql = mysqli_query($con,"SELECT * FROM product_description
WHERE product_id='$item_id' LIMIT 1");
while ($row = mysqli_fetch_array($sql)) {
$product_name = $row["name"];
$msg .= "<td>$product_name</td>";
// Other message parts go here
}
$msg .= "End of message\n";
Alternately, you can go a very terrible route and use something like eval, but because I discourage such behavior I will not be providing an example.
You're not escaping the quotes in $message. use ' or \" for html instead. Also you don't need the extra PHP tags in the middle of $message as you're still writing in PHP. Inside your foreach concatenate $message with .= and by the end it will be a string which you can submit with your email. I haven't tested it but I cleaned up your code and made the suggested changes below.
$message = "
<html>
<body>
<p> This doesn't render well</p>
<table style="margin-left:50px; text-align:left;">
<tr>
...
Should be
$message = "
<html>
<body>
<p> This doesn't render well</p>
<table style=\"margin-left:50px; text-align:left;\">
<tr>
...
Here you go
<?php
$to = "member#yahoo.com";
$from = "sales#thesite.com";
$headers = "From: $from";
$subject = "Custom computer Order Confirmation Nunber_ $orderid";
$message = "<html>
<body>
<p>This doesn't render well</p>
<table style=\"margin-left:50px; text-align:left;\">
<tr>
<th style=\"width:20%; border-bottom:solid 1px #000\">Item ID</th>
<th style=\"width:40%; border-bottom:solid 1px #000\">Description</th>
<th style=\"width:15%; border-bottom:solid 1px #000\">Quantity</th>
<th style=\"width:20%; border-bottom:solid 1px #000\">Unit Price</th>
</tr>";
foreach( $_SESSION["cart_array"] as $item )
{
$item_id = $item["part_id"];
$sql = mysqli_query( $con, "SELECT * FROM product_decsription WHERE product_id='".$item_id."' LIMIT 1;" );
if($row=mysqli_fetch_array($sql))
{
$message .= "
<tr><td>".$item['part_id']."</td>
<td>".$row['name']."</td>
<td>".$item['quantity']."</td>
<td>".$item['price']."</td></tr>";
}
}
$message .= "</table></body></html>";
$mailsent = mail( $to, $subject, $message, $headers );
?>
EDIT: the headers to use html need to be:
$headers = "From: ".$from."\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

Categories