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";
Related
I am trying to retrieve data from mysql database that has 4 rows. I need to send this as an table in email using php. I have built a script for this, but the issue is the script is not emailing all the rows, its just emailing the last row or if i pass a specific parameter with "where" in db query.
Any help from anyone is appreciated. Thank you in advance.
Attached the db output and php code as well.
<?php
date_default_timezone_set('America/Los_Angeles');
$today = date("j-F-Y g:i:s a"); // March 10, 2001, 5:16 pm
// DB Connect.
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = 'test123#'; // Password
$db_name = 'util'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "select * from srvr1";
$result = mysqli_query($conn, $sql);
if (!$result) {
die ('SQL Error: ' . mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
$File_system = $row[0];
$IP = $row[1];
$Capacity = $row[2];
$Available = $row[3];
$Used = $row[4];
$Percentage = $row[5];
# Compare Percentage and alert.
$subject = "Critical | FH NetApp-NetBackup Space Utilization..!";
$message1 = "
<html>
<body>
<p> Hi Team,<br><br> The Server utilization is <b style='color:red'> critical</b>. Please find the below utilization details.</p>
<table>
<tr>
<th> File_System </th>
<th> IP </th>
<th> Total_capacity </th>
<th> Available_Capacity </th>
<th> Used_Capacity </th>
<th> Percentage </th>
</tr>
<tr>
<td> $File_system </td>
<td> $IP </td>
<td> $Capacity </td>
<td> $Available </td>
<td> $Used </td>
<td> $Percentage </td>
</tr>
</table>
<p style='font-size:15px'> Data generated at:<b> $today EST.</b><p>
<p>Regards, <br>
Backup Team. </p>
</body>
</html>";
$headers[] = 'From: Srvr19utilization#util.com'; // Sender's Email
$headers[] = 'Cc: santosh.kowshik20#gmail.com'; // Carbon copy to Sender
$headers[] = 'MIME-Version: 1.0 charset=".$encoding."';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message1, 70);
// Send Mail By PHP Mail Function
mail($to, $subject, $message, implode("\r\n", $headers));
}
}
?>
I have been trying to shuffle around the loop in the code, it did not help.
Try and rearrange your code a little bit. First create the 'top' of the html, then go through all the results and append them to the html and then finish the html.
I haven't tested the code beneath but it should work :-)
<?php
date_default_timezone_set('America/Los_Angeles');
$today = date("j-F-Y g:i:s a"); // March 10, 2001, 5:16 pm
// DB Connect.
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = 'test123#'; // Password
$db_name = 'util'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "select * from srvr1";
$result = mysqli_query($conn, $sql);
if (!$result) {
die('SQL Error: ' . mysqli_error($conn));
}
if (mysqli_num_rows($result) > 0) {
$subject = "Critical | FH NetApp-NetBackup Space Utilization..!";
$message1 = "
<html>
<body>
<p> Hi Team,<br><br> The Server utilization is <b style='color:red'> critical</b>. Please find the below utilization details.</p>
<table>
<tr>
<th> File_System </th>
<th> IP </th>
<th> Total_capacity </th>
<th> Available_Capacity </th>
<th> Used_Capacity </th>
<th> Percentage </th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
$File_system = $row[0];
$IP = $row[1];
$Capacity = $row[2];
$Available = $row[3];
$Used = $row[4];
$Percentage = $row[5];
# Compare Percentage and alert.
$message1 .= "
<tr>
<td> $File_system </td>
<td> $IP </td>
<td> $Capacity </td>
<td> $Available </td>
<td> $Used </td>
<td> $Percentage </td>
</tr>";
}
$message1 .= "</table>";
$message1 .= "<p style='font-size:15px'> Data generated at:<b> $today EST.</b><p>
<p>Regards, <br>
Backup Team. </p>
</body>
</html>";
$headers[] = 'From: Srvr19utilization#util.com'; // Sender's Email
$headers[] = 'Cc: santosh.kowshik20#gmail.com'; // Carbon copy to Sender
$headers[] = 'MIME-Version: 1.0 charset=".$encoding."';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message1, 70);
// Send Mail By PHP Mail Function
mail($to, $subject, $message, implode("\r\n", $headers));
}
?>
About conditional formatting
No worries. You can try and use nested ternaries (shorthand for if/else... to keep it short :-))
Example snippet from above code:
...
$Percentage = $row[5];
$color = ($Percentage > 90) ? '#FCE901' : (($Percentage > 85) ? '#FF0000' : '#00E526');
# Compare Percentage and alert.
$message1 .= "
<tr>
<td> $File_system </td>
<td> $IP </td>
<td> $Capacity </td>
<td> $Available </td>
<td> $Used </td>
<td style=\"background-color:$color\"> $Percentage </td>
</tr>";
The issue is somewhere on your database end. Based on your var_dump output:
object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(6) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) }
You only have 1 result being returned. You should start there. Maybe you're not referencing the table you think you are. Who knows right now, but you php looks fine. Investigate your DB
Your PHP is not fine stubben gave you the answer
<?php
date_default_timezone_set('America/Los_Angeles');
$today = date("j-F-Y g:i:s a"); // March 10, 2001, 5:16 pm
// DB Connect.
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = 'test123#'; // Password
$db_name = 'util'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn)
{
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = "select * from srvr1";
$result = mysqli_query($conn, $sql);
if (!$result)
{
die ('SQL Error: ' . mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$File_system = $row[0];
$IP = $row[1];
$Capacity = $row[2];
$Available = $row[3];
$Used = $row[4];
$Percentage = $row[5];
Above You have a Percentage from 1 Row of Data
Below you use that to decide the eMail subject - only 1 subject per email - so 1 row of data per email
# Compare Percentage and alert.
if($Percentage > 90)
{
$subject = "Critical | FH NetApp-NetBackup Space Utilization..!";
$message1 = "
<html>
<head>
<style>
body,h6 {
font-family: Segoe UI,Helvetica,courier;
}
th {
border: 1px solid black;
border-collapse: collapse;
background-color: #04D1E8;
padding: 10px;
text-align: center;
}
td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
text-align: center;
}
.cri {
background-color: #FF0000;
}
</style>
</head>
<body>
<p> Hi Team,<br><br> The Server utilization is <b style='color:red'> critical</b>. Please find the below utilization details.</p>
<table>
<tr>
<th> File_System </th>
<th> IP </th>
<th> Total_capacity </th>
<th> Available_Capacity </th>
<th> Used_Capacity </th>
<th> Percentage </th>
</tr>
<tr>
<td> $File_system </td>
<td> $IP </td>
<td> $Capacity </td>
<td> $Available </td>
<td> $Used </td>
<td class='cri'> $Percentage </td>
</tr>
</table>
<p style='font-size:15px'> Data generated at:<b> $today EST.</b><p>
<p>
Regards, <br>
Backup Team.
</p>
</body>
</html>
";
$headers[] = 'From: Srvr19utilization#util.com'; // Sender's Email
$headers[] = 'Cc: santosh.kowshik20#gmail.com'; // Carbon copy to Sender
$headers[] = 'MIME-Version: 1.0 charset=".$encoding."';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message1, 70);
// Send Mail By PHP Mail Function
mail($to, $subject, $message, implode("\r\n", $headers));
}
else if($Percentage > 85)
{
$subject = "Warning | FH NetApp-NetBackup Space Utilization..!";
$message1 = "
<html>
<head>
<style>
body,h6{
font-family: Segoe UI,Helvetica,courier;
}
th {
border: 1px solid black;
border-collapse: collapse;
background-color: #04D1E8;
padding: 10px;
text-align: center;
}
td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
text-align: center;
}
.war {
background-color: #FCE901;
}
</style>
</head>
<body>
<p> Hi Team,<br><br> The Server utilization is <b style='color:yellow'> above normal</b>. Please find the below utilization details.</p>
<table>
<tr>
<th> File_System </th>
<th> IP </th>
<th> Total_capacity </th>
<th> Available_Capacity </th>
<th> Used_Capacity </th>
<th> Percentage </th>
</tr>
<tr>
<td> $File_system </td>
<td> $IP </td>
<td> $Capacity </td>
<td> $Available </td>
<td> $Used </td>
<td class='war'> $Percentage </td>
</tr>
</table>
<p style='font-size:15px'> Data generated at:<b> $today EST.</b></p>
<p>
Regards, <br>
Backup Team.
</p>
</body>
</html>
";
$headers[] = 'From: Srvr19utilization#util.com'; // Sender's Email
$headers[] = 'Cc: santosh.kowshik20#gmail.com'; // Carbon copy to Sender
$headers[] = 'MIME-Version: 1.0 charset=".$encoding."';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message1, 70);
// Send Mail By PHP Mail Function
mail($to, $subject, $message, implode("\r\n", $headers));
}
else
{
$subject = "Normal | FH NetApp-NetBackup Space Utilization..!";
$message1 = "
<html>
<head>
<style>
body,h6{
font-family: Segoe UI,Helvetica,courier;
}
th {
border: 1px solid black;
border-collapse: collapse;
background-color: #04D1E8;
padding: 10px;
text-align: center;
}
td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
text-align: center;
}
.nor {
background-color: #00E526;
}
</style>
</head>
<body>
<p> Hi Team,<br><br> The Server utilization is <b style='color:green'> normal. </b>Please find the below utilization details.</p>
<table>
<tr>
<th> File_System </th>
<th> IP </th>
<th> Total_capacity </th>
<th> Available_Capacity </th>
<th> Used_Capacity </th>
<th> Percentage </th>
</tr>
<tr>
<td> $File_system </td>
<td> $IP </td>
<td> $Capacity </td>
<td> $Available </td>
<td> $Used </td>
<td class='nor'> $Percentage </td>
</tr>
</table>
<p style='font-size:15px'> Data generated at:<b> $today EST.</b></p>
<p>
Regards, <br>
Backup Team.
</p>
</body>
</html>
";
$headers[] = 'From: Srvr19utilization#util.com'; // Sender's Email
$headers[] = 'Cc: santosh.kowshik20#gmail.com'; // Carbon copy to Sender
$headers[] = 'MIME-Version: 1.0 charset=".$encoding."';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message1, 70);
// Send Mail By PHP Mail Function
mail($to, $subject, $message, implode("\r\n", $headers));
}
}
}
?>
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);
}
?>
Im trying to send a mail attachment in php.
Here is the code which im trying but dont know whats wrong in this:
please can anyone suggest any modification for the following code
<?php
$path = "files/";
$files = "myfile.csv";
$par_mailto = "RECEIVER MAIL ID";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
$file = fopen($path.$files,"rb");
$data = fread($file,filesize($path.$files));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
//mail attachment ends
$date = date_default_timezone_set('Asia/Kolkata');
$today = date("F j, Y, g:i a T");
$subject = "Test mail on ".$today ;
$header .= 'MIME-Version: 1.0' . "\r\n". 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = $header."From: info#ziddu.com ". "\r\n"
. "Cc: $par_mailcc" . "\r\n";
//!!!All the emails are coming with comma as separator .... "\r\n\" is important to separate FROM Cc BCc.
$message .= "<html><body>";
//
$message .= "<table width='800' cellspacing='5' cellpadding='5' border='0' align='center' style='border:1px solid #e6e6e6'>
<tbody><tr>
<td height='80' bgcolor='#F3F3F3' style='padding-left:15px'><table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tbody><tr>
<td width='50%' align='center'></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td valign='top' height='150'>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>Dear Mr. ".$_SESSION['name'].",</p>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>This is the test mail with an attachment</b></p>
";
$message .= "
<div style='width:584px;background-color:#ffffff;border:#e8e7e7 solid 1px;padding:27px 0;margin:0 auto;border-bottom:0'>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:0px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='400px'> <span style='color:#333333;font-weight:600'>Transaction Details: </span></td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Transfered </td>
<td>USD 10000</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Fee</td>
<td>USD 200</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Total</td>
<td>USD 4000</td>
</tr>
</tbody>
</table>
</div>
<div style='font:normal 12px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 0px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
</tbody>
</table>
</div>
</div>
<div style='margin:0 auto;width:594px'><img alt='' src='https://ci4.googleusercontent.com/proxy/Rku_qr-ooNg8yw1tsELcIxO6HBPXzNZtY_bfb9r8yySSxzteTaIxDoJ83pE5XmtwvZO7O5UC4wM31f_rVlP6HyR9VK2OrStgu8llNx45_L81Jv7YD6P1=s0-d-e1-ft#https://dx87hk8eoofvk.cloudfront.net/images/email/receiptedge.png' title=''></div>";
$message .="<p style='font-family:verdana'><br><b>IMPORTANT:</b>"
. " Please do not reply to this message or mail address. For any queries,please mail to info#ziddu.com \n\n</p>";
$message .="<p style='font-family:verdana'><b>DISCLAIMER:</b>"
. " This communication is confidential and privileged and is directed to and for the use of the addressee only. "
. "The recipient if not the addressee should not use this message if erroneously received, "
. "and access and use of this e-mail in any manner by anyone other than the addressee is unauthorized. "
. "The recipient acknowledges that Ziddu.com may be unable to exercise control or ensure or guarantee the "
. "integrity of the text of the email message and the text is not warranted as to completeness and accuracy. "
. "\n\n</p><br>";
$message .="<p style='font-family:verdana'>Regards,<br>Ziddu Team <br>www.ziddu.com \n\n</p>";
$message .="</td>
</tr>
<tr>
<td height='30' bgcolor='#E9E9E9' align='center'><strong>Upload.. Share.. Earn!</strong></td>
</tr>
</tbody></table>";
#mail($par_mailto, $subject, $message, $headers);
?>
As i need to add some more information with design and all also had an attachment that needs to be attached. Got confused where im gone wrong
I'm working in PHP and I have a simple shopping cart which adds items when you click the add button.
Everything is collected in a variable called $cartOutput
When I echo it, it gives me everything in the cart as expected. Same with var_dump . Everything is there
However, when I try to put it in an email and send it off. It cuts off the first item. Can anyone think of why this might be?
Nothing filters it before it is put into the email. It is simply what is in the variable
here is an example...
// e.g of the php variable being assembled for each item
$cartOutput .= "<tr>";
$cartOutput .= "<td>" . $product_name . "</td>";
$cartOutput .= "<td>$" . $price . "</td>";
// emailing the variables off here
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$company = $_POST['company'];
$name = $_POST['name'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$commercialAdd = $_POST['commercial'];
$residentialAdd = $_POST['residential'];
$city = $_POST['city'];
$province = $_POST['province'];
$postal_code = $_POST['postal_code'];
$email = $_POST['email'];
$special_instructions = $_POST['special_instructions'];
$date = date("Y/m/d");
$time = date("h:i:sa");
$to = "xxx#gmail.com";
$header = "Cc:xxx#somedomain.com \r\n";
$subject = "Email Order - $company ($date - $time)";
$message = <<<EOD
<h1>Email Order - $date - $time </h1>
<h3><strong><u>Company:</u></strong> $company</h3>
<h3><strong><u>Name:</u></strong> $Name </h3>
<h3><strong><u>Address:</u></strong> $address<br>
$address2</h3>
<h3><strong><u>Residential:</u></strong> $commercialAdd </h3>
<h3><strong><u>Commercial:</u></strong> $residentialAdd </h3>
<h3><strong><u>City:</u></strong> $city</h3>
<h3><strong><u>Province:</u></strong> $province</h3>
<h3><strong><u>Postal Code:</u></strong> $postal_code</h3>
<h3><strong><u>Phone Number:</u></strong> $phone</h3>
<h3><strong><u>Email:</u></strong> $email</h3>
<h3><strong><u>Special Instructions:</u></strong> $special_instructions</h3>
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Weight (Kg)</th>
<th>Qty</th>
<th>Subtotal</th>
<th></th>
</tr>
</thead>
<tbody>
$cartOutput
<tr>
<td class="totals"><strong>Total</strong></td>
<td class="totals"> </td>
<td class="totals">$weightTotal kg</td>
<td class="totals">$quantityTotal</td>
<td class="totals">$ $cartTotal</td>
<td class="totals"> </td>
<tr>
</tbody>
</table>
EOD;
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
header("location: complete.php");
exit();
}
else {
echo "Order could not be sent. Please try again or contact our office for assistance";
}
}
Probably you are running into an email format issue. mail() requires the body to end each line in \r\n AND be less than 70 characters each. You will need to encode you HTML or include it as an attachment. See this set of instructions for an example.
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.