I am trying to send booking confirmation email to client. I've made a confirmation template using HTML and CSS where some data are generated from a php form. I am facing two problem now.(1) When i generate the template, instead and showing the template it shows only the SUBMIT button.(2) and without clicking the button the confirmation template automatically goes to the client email with the raw code of HTML and CSS. It does not shows the template in client's email. Can anyone help me to fix this? Note that i kept all my HTML and CSS code in a php variable ( $message ).
<?php $message= '<!DOCTYPE html>
<html>
<head> </head>
<body>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style type="text/css">
table {
width:100%;
}
table, th, td {
border: 2px solid #ffffff;
border-collapse: collapse;
}
</style>
<body>
<div class="table">
<table id="t01">
<tr>
<td><?php echo $_POST["guestname"]; ?></td>
<td><?php echo $_POST["checkin"]; ?></td>
<td><?php echo $_POST["checkout"]; ?></td>
<td><?php echo $_POST["roomtype"]; ?></td>
<td><?php echo $_POST["rate"]; ?></td>
<td><?php echo $_POST["payment"]; ?></td>
<td><?php echo $_POST["resno"]; ?></td>
</tr>
</table>
</div> <!-- table -->
'; ?>
<?php
$to = "client#email.com";
$subject = "My subject";
$txt = "$message";
$headers = "From: my#email.com" . "\r\n" .
mail($to,$subject,$txt,$headers);
?>
<input type="submit" value="Send" />
In your sending code you need to specify the content type of the mail and send it as a header, additionally you need to modify your PHP code like so
<?php
$message = '<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style type="text/css">
table {
width:100%;
}
table, th, td {
border: 2px solid #ffffff;
border-collapse: collapse;
}
</style>
</head>
<body>
<div class="table">
<table id="t01">
<tr>
<td>'.$_POST["guestname"].'</td>
<td>'.$_POST["checkin"].'</td>
<td>'.$_POST["checkout"].'</td>
<td>'.$_POST["roomtype"].'</td>
<td>'.$_POST["rate"].'</td>
<td>'.$_POST["payment"].'</td>
<td>'.$_POST["resno"].'</td>
</tr>
</table>
</div> <!-- table -->
</body>
</html>';
//Set the headers and other mail data and mail it
$to = 'client#email.com';
$subject = 'My subject';
// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'From: my#email.com';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
?>
For further reference read the documentation
Change your tr tag like this
<tr>
<td>'.$_POST["guestname"].'</td>
<td>'.$_POST["checkin"].'</td>
<td>'.$_POST["checkout"].'</td>
<td>'.$_POST["roomtype"].'</td>
<td>'.$_POST["rate"].'</td>
<td>'.$_POST["payment"].'</td>
<td>'.$_POST["resno"].'</td>
</tr>
Your are using php tag inside php tag which is wrong
Remove <?php code inside <?php. Also set content type in mail header
try this:
<?php $message= '<!DOCTYPE html>
<html>
<head> </head>
<body>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style type="text/css">
table {
width:100%;
}
table, th, td {
border: 2px solid #ffffff;
border-collapse: collapse;
}
</style>
<body>
<div class="table">
<table id="t01">
<tr>
<td>'.$_POST["guestname"].'</td>
<td>'.$_POST["checkin"].'</td>
<td>'.$_POST["checkout"].'</td>
<td>'.$_POST["roomtype"].'</td>
<td>'.$_POST["rate"].'</td>
<td>'.$_POST["payment"].'</td>
<td>'.$_POST["resno"].'</td>
</tr>
</table>
</div> <!-- table -->
'; ?>
<?php
$to = "client#email.com";
$subject = "My subject";
$txt = "$message";
$headers = "From: my#email.com" . "\r\n" ;
mail($to,$subject,$txt,$headers);
?>
Related
The below code gives the output as how in screenshot. I want to send this content via php mail function . When i try to add this code into $message , It doesnt work as it contains php code(to retrieve data from table) in between html code. Kindly help on how this can be achieved ?
This is the code i was trying out for email .
<?php
include('db.php'); //connection to database
$to = 'example#gmail.com';
$subject = "test php mail" ;
$message = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta charset="utf-8">
<title> Fetching data </title>
</head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th{
color:#DC143C;
}
td {
color:#0000FF;
}
</style>
<body>
<font size="4" face="Courier New" >
<table border="1" style="width:50%" align="center">
<tr bgcolor="#2ECCFA">
<th style="padding: 20px" bgcolor="#E6E6FA"
color="#DC143C" color="red">Word of the Day</th>
</tr>
<!-- I used while loop to fetch data and display rows of date on html
table -->
<?php
$records = mysql_query("SELECT * FROM hindiday order by
rand(curdate())
limit 1 ");
while ($course = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$course['hindiword'] . ' ' .$course['phonetic'] . ' '
.$course['id']." </td>"; "</tr>" ;
}
?>
</table>
</body>
</html> ' ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: abc#gmail.com.com>' . "\r\n";
// Send email
if(mail($to,$subject,$message,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
I would suggest looping outside the string, and the concatenate the result like so :
$string = ''; // The variable used to contain your data
$records = mysql_Something is wrong("SELECT * FROM hindiday order by rand(curdate()) limit 1 ");
while ($course = mysql_fetch_assoc($records)){
//Filling that variable
$string .= "<tr>";
$string .= "<td>".$course['hindiword'] . ' ' .$course['phonetic'] . ' ' .$course['id']." </td>"; "</tr>" ;
}
//Using the variable in your message
$message = '
...
'. $string .'
...
';
That way wherever you want to add the $string you just concatenate it, as if you try to execute PHP code inside a string it'll be considered as a string and the PHP in question won't be executed.
So the final result would look like this :
<?php
include('db.php'); //connection to database
$to = 'example#gmail.com';
$subject = "test php mail" ;
$string = ''; // The variable used to contain your data
$records = mysql_Something is wrong("SELECT * FROM hindiday order by rand(curdate()) limit 1 ");
while ($course = mysql_fetch_assoc($records)){
//Filling that variable
$string .= "<tr>";
$string .= "<td>".$course['hindiword'] . ' ' .$course['phonetic'] . ' ' .$course['id']." </td>"; "</tr>" ;
}
$message = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta charset="utf-8">
<title> Fetching data </title>
</head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th{
color:#DC143C;
}
td {
color:#0000FF;
}
</style>
<body>
<font size="4" face="Courier New" >
<table border="1" style="width:50%" align="center">
<tr bgcolor="#2ECCFA">
<th style="padding: 20px" bgcolor="#E6E6FA"
color="#DC143C" color="red">Word of the Day</th>
</tr>
<!-- I used while loop to fetch data and display rows of date on html
table -->
'. $string .'
</table>
</body>
</html> ' ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: abc#gmail.com.com>' . "\r\n";
// Send email
if(mail($to,$subject,$message,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
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 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
This question already has answers here:
Send HTML in email via PHP
(8 answers)
Closed 7 years ago.
I am setting up a confirmation email script for our customers to receive an email when they complete the online form. I uploaded my script and tested but I received an email with just the raw HTML. I have been looking at some tutorials trying to do this as well. I validated my HTML and I passed all the tests. Is there something that I have to include in my PHP for my body string to be interpreted as HTML?
Here is my script
<?php
//Script for sending a confirmation email
$body = "<!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>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
<title>Demystifying Email Design</title>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>
</head>
<body style=\"margin: 0; padding: 0; background-color: #ecf0f1;\">
<table cellpadding=\"0\" cellspacing=\"0\" width=\"60%\" align=\"center\" style=\"border: 1px solid #bdc3c7;\">
<tr bgcolor=\"#3498db\">
<td align=\"center\">
<img alt=\"Logo\" src=\"http://www.****.com/logo-lg.jpg\" style=\"width: 50%; height: auto; padding-top: 5%; padding-bottom: 5%;\" />
</td>
</tr>
<tr bgcolor=\"#ffffff\" align=\"center\">
<td>
<h3 style=\"padding-top: 5%; padding-bottom: 5%;\">Worldwide innovator in flexible liquid packaging</h3>
</td>
</tr>
<tr align=\"center\" bgcolor=\"#ffffff\">
<td>
<h4 style=\"padding-top: 5%; padding-bottom: 5%;\">Thank you for contacting customer service. We've received your sample request; one of our team members will be in contact with you in the very near future. Thanks again for your time and interest.</h4>
</td>
</tr>
</table>
</body>
</html>";
$to = "*******#****.com";
$subject = "Thanks for Reaching out";
if (mail($to,$subject,$body)){
echo "Mail was sent";
} else{
echo "Failed";
}
This is the email I received
You need to also set a header indicating this is HTML, e.g.
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Source (see Example 3).
Correct code will be:
$to = "*******#****.com";
$subject = "Thanks for Reaching out";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if (mail($to,$subject,$body,$headers)){
echo "Mail was sent";
}
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.