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
Related
I have a page where users select a product (products come from sql database) and input a quantity needed. They then view a "cart" page and submit the order which just sends a email to me with the details. I am trying to automatically update the quantity in the sql database when they submit the order.
I think I would have to do something like the following, but I am new to php and sql. I would have to take the original quantity from the DB and subtract the "ordered quantity" which is entered by the user and displayed on the cart page and set that new value. Can anyone shed some light on how I might accomplish this?
What I think I have to do?:
$updquery = 'UPDATE "products" SET "Quantity"= "Quantity" - '. $product['quantity'] .' WHERE PID = '. $product['id'] .' ';
cart.php
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
?>
<?php
#session_start();
if(isset($_POST['logout'])) {
unset($_SESSION['shopping_cart']);
}
if(isset($_POST['submit'])) {
$email = $_POST['email'];
// Create the email and send the message
$to = 'myemail#gmail.com'; // Add your email address inbetween the ''
replacing yourname#yourdomain.com - This is where the form will send a
message to.
$email_subject = "Products Order - ".$_POST['email']."";
// PREPARE THE BODY OF THE MESSAGE
$email_body = '<html><body>';
$email_body .= '<h1 style="text-align:center;">Products List</h1>';
$email_body .= '<table rules="all" style="border-color: #666;margin:
auto;" border="1" cellpadding="10">';
$email_body .= '<tr><th colspan="2"><h3>Requested Parts</h3></th>
</tr>';
$email_body .= '<tr><th width="100" align="left">Product ID</th><th
width="100" align="right">Quantity</th></tr>';
foreach($_SESSION['shopping_cart'] as $key => $product):
$email_body .= '<tr><td>'. $product['id'] .'</td><td
align="right">'. $product['quantity'] .'</td></tr>';
endforeach;
$email_body .= "</table>";
$email_body .= "</body></html>";
$headers = "From: myemail#gmail.com\n"; // This is the email address
the generated message will be from. We recommend using something like
noreply#yourdomain.com.
$headers .= "Reply-To: ".$_POST['email']."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
mail($to,$email_subject,$email_body,$headers);
unset($_SESSION['shopping_cart']);
?>
<script>
alert("Your order has been submitted")
window.location.href = "index.php"
</script>
<?php
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inventory Cart</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/icon.ico" type="image/x-icon">
<style>
*{
margin :auto;
}
table {
border-collapse: collapse;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
tr:nth-child(even) {
background-color: #eee;
}
tr:nth-child(odd) {
background-color: #fff;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Cart</h1>
<?php
if(!empty($_SESSION['shopping_cart'])){ ?>
<div class="table-responsive" style="background:white;">
<table class="table table-responsive" id="mytable" border="1"
align="center">
<tr><th colspan="2"><h3>Requested Parts</h3></th></tr>
<tr>
<th width="100" align="left">Product ID</th>
<th width="100" align="right">Quantity</th>
</tr>
<?php
foreach($_SESSION['shopping_cart'] as $key => $product):
?>
<tr>
<td><?php echo $product['id']; ?></td>
<td align="right"><?php echo $product['quantity']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
<div style="text-align:center;">
<form action="" method="post">
<input type="email" size="31" name="email" placeholder="Please enter
your email address" required /><br>
<input type="submit" name="submit" value="Submit" id="btnSubmit"/>
</form>
<form action="" method="post">
<input type="submit" name="logout" value="Clear" id="btnClear" />
</form>
</div>
</div>
<?php
}
else{
?>
<script>
alert("Cart is empty")
window.location.href = "index.php"
</script>
<?php
}
?>
<br><br>
</body>
</html>
You provided your own answer (query):
1) Set up mysql connection in the beginning of your script:
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
2) In your foreach, add the query to update each os the product's quantity as you add them to the e-mail. Becomes:
foreach($_SESSION['shopping_cart'] as $key => $product):
$email_body .= '<tr><td>'. $product['id'] .'</td><td align="right">'. $product['quantity'] .'</td></tr>';
mysqli_query($con,'UPDATE products SET Quantity = Quantity - '. $product['quantity'] .' WHERE PID = '. $product['id'] .' ');
endforeach;
mysqli_close($con);
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);
}
?>
I wanted to send unique confirmation link to multiple users, that user list get from the database mysql. I tried using the following code, but it send only the first user not all.
<?php
$get_ref_q = mysql_query("select * from $referal_details where ser_fk='$last_insert_id'");
$get_last_ref_value = mysql_num_rows($get_ref_q);
$z=1;
if($get_last_ref_value > 0)
{
//$user_email = array();
while($sel_per_fet = mysql_fetch_assoc($get_ref_q))
{
$rf_name = $sel_per_fet['rf_name'];
$dy_link = $sel_per_fet['dy_link'];
$user_email = $sel_per_fet['rf_email'];
$userhtml = '<html>
<body style="width:100%; font-family:Arial; font-size:13px; line-height:22px; background:#fff; position:relative;color:#555555; margin:0px; padding:0px;">
<div style="margin:0 auto; width:600px;">
<div style="background:#fff; width:594px; float:left;border:#2fb25d 3px solid;">
<div style="padding:27px; width:540px; float:left;text-align:center; border-bottom:#2fb25d 3px solid;">
</div>
<div style="background:#fff; padding:44px 34px; width:526px; float:left;">
<h1 style="color:#000; font-size:20px; font-family:Arial; font-weight:normal; margin-bottom:20px;">
Dear '.$rf_name.' <br />
</h1>
<p>Vetri has refered you for this servey</p>
<p>please find your servey link</p>
<p>'.$uri.'/index.php?token='.$dy_link.'</p>
</div>
</div>
</div>
</body>
</html>';
$user_subject = 'Vetri has refered you for this servey';
$user_message = $userhtml;
$user_headers .= 'MIME-Version: 1.0' . "\r\n";
$user_headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$user_headers .= "From: Servey <$comp_email> \r\n";
mail($user_email,$user_subject,$user_message,$user_headers,"-f$comp_email");
$z++;
}
}
?>
Note: I already have $last_insert_id value. I wanted to send unique email content to each users, not the common contend. Thanks in advance.
Your code looks good - apart from one tiny issue:
$user_headers .= 'MIME-Version: 1.0' . "\r\n";
---------------^
This line does not need the ., and it is likely that subsequent emails are adding more and more identical headers to $user_headers, causing subsequent messages to fail.
i am using php to send a html email like so in my send_email.php file:
<?php
// multiple recipients
$to = 'mark.obrien2014#inbox.com';
// subject
$subject = 'Hewden New Supplier Setup';
// message
$message = file_get_contents('../../assets/email/email.php');
// 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 .= 'To: Mark <mark.obrien2014#inbox.com>' . "\r\n";
$headers .= 'From: Hewden New Supplier Setup <NewSuppliers#hewden.co.uk>' . "\r\n";
$headers .= 'Cc: purchasing#hewden.co.uk' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I am including my email html in a seperate file email.php using
$message = file_get_contents('../../assets/email/email.php');
I am testing my email has been sent using Outlook 2010 on windows and also testing it in a normal webmail. The email sends fine on both but in outlook the html doesn't seem to display properly. My email looks fine in every other email program and all other webmail. can someone please show me what i am doing wrong? thanks in advance
my email html:
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body leftpadding="0" offset="0" paddingheight="0" paddingwidth="0" toppadding="0" style="padding-top: 0; padding-bottom: 0; padding-top: 0; padding-bottom: 0; background:#F6F6F6; width: 100% !important; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; -webkit-font-smoothing: antialiased;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table align="center" class='bgBody' border="0" cellpadding="0" cellspacing="0" style="font-family:helvetica, sans-serif; background:#fff; border:1px solid #999; margin-top:50px;" width="750">
<tr>
<td align="center">
<img src="http://hewdenportal.co.uk/assets/email/images/bigImg.png" width="750" height="258" />
</td>
</tr>
</table>
</tr>
</table>
<table align="center" class='bgBody' border="0" cellpadding="0" cellspacing="0" style="font-family:helvetica, sans-serif; font-weight:100; font-size:16px; background:#000; color:#4f4f4f; border:1px solid #999; margin-top:20px;" width="752">
<tr>
<td align="left">
<div class="container" style="min-height:200px; width:690; background:#fff; padding-left:30px; padding-right:30px; padding-top:20px; padding-bottom:20px; font-family:helvetica, sans-serif; font-weight:100; font-size:15px;">
<div class="text" style="width:72%;">
<h1 style="font-family:helvetica, sans-serif; font-weight:100; font-size:20px;">Getting Started</h1>
<p>Thanks for taking an Interest in joining Hewden as an approved supplier.<br/>We care about providing a good quality to service to Customer's and Supplier's alike.</p>
<p>As part of the Hewden journey blah blah blah.</p>
</div>
<div class="find_more" style="width:110px; border:1px solid #666; height:20px; background:rgba(255,195,82,1); margin-top:10px; float:right; position:relative; cursor:pointer; cursor:hand; text-align:center; padding:6px;">Find out More ></div>
</div>
</td>
</tr>
</table>
</body>
</html>
email in webmail showing correct html:
email in outlook with distorted html:
Use or <button> tags instead of a <div> tag.
As far as I know (I send HTML emails pretty often), buttons are well more accepted on Outlook and other email providers.
HTML emails are very annoying sometimes... :)
Using div in html emails is a little tricky and if you can get away with table that'd be easier in general. I would guess the specific issue here is that Outlook 2010 doesn't support width, position, or float for div. Campaign Monitor wrote a nice roundup of div compatibility here.
I'm trying to send an email to myself that has a layout and images. What I'm I doing wrong?
<?php
$message = $_POST['message'];
$emailsubject = 'site.com';
$webMaster = 'email#site.com';
$body = "
<html>
<body bgcolor=\"e7e7e7\">
<style type=\"text/css\">
#body {margin: auto;border: 0;padding: 0;font-family: Georgia, 'Times New Roman', Times, serif;font-size: 12px;}
#emailHeader {width: 500px;height: 131px;background: url(http://www.site.com/images/image.gif) no-repeat;}
#emailContent {width: 500px;background: url(http://www.site.com/images/image2.gif) repeat-y;text-align: left;padding: 0 33px 0 6px;}
#emailFooter {width: 500px;height: 34px;background: url(http://www.site.com/images/image3.gif) no-repeat;}
</style>
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td valign=\"top\" align=\"center\">
<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td id=\"emailHeader\"></td>
</tr>
<tr>
<td id=\"emailContent\">
content $message
</td>
</tr>
<tr>
<td id=\"emailFooter\"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>"
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailsubject, $body, $headers);
if ($success) {
echo "Your message was sent.";
}
else{
echo "There was a error.";
}
?>
You should use phpmailer instead of PHP's mail()-Function. It allows you to easily send HTML-Mails.
Besides that you can try to validate your HTML-Code to be compatible for emailing.
Best wishes,
Fabian
You have an error in your code:
WRONG
$headers .= "Content-type: text/html\r\n";
RIGHT
$headers = "Content-type: text/html\r\n";
The .= throws a parse error in PHP unless you previously set $headers somewhere else.
It also may depend on the email client you are testing with. Be sure to check out http://www.email-standards.org/ to check what your email client supports.
You may also want to look into Zend_Mail from Zend Framework:
http://framework.zend.com/manual/en/zend.mail.html
Would make dealing with headers, formats, MIME, etc. easier.