I have tried several diffrent codes to have php send the form and have the mail alighned on right, and nothnig works. When I open the mail, it is always on left
<?php
$to = "skatz25#hotmail.com";
$subject = "טופס הפניית מתנדב/ גוף פונה";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$rname = $_POST['rname'];
$date = $_POST['date'];
$name = $_POST['name'];
$age = $_POST['age'];
$refrence = $_POST['refrence'];
$msg = '
<html>
<body dir="rtl">
<table dir="rtl" style="direction:rtl">
<tr>
<td style="text-align: right;">מקבל הפנייה:</td>
<td>' . $rname . '</td>
<tr>
</table>
</body>
<html>
';
mail($to, $subject, $msg, $headers);
?>
When I open the mail in hotmail the text is rtl but starts from the left side of the page instead of the right
Any help is appreciated
First, you must draw a table that has width and heigth set to 100% and in that table, create another table, aligned to the right, like: <table width='100%' height='100%'><tr><td align='right'> <table align='right'><tr><td>content</td></tr></table> </td></tr></table>
Try adding a width to the table.
Related
I have the following mail script with the structure shown below:
<?php
$to = 'example#testing';
$subject = 'Testing';
$from = 'test#email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi!</h1>';
$message .= '<p style="color:#080;font-size:18px;">This is a test.</p>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
I then would like to put the following table inside the body as well but when adding the following, the PHP does not work:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
tr.header
{
font-weight:bold;
}
tr.alt
{
background-color: #777777;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('.striped tr:even').addClass('alt');
});
</script>
<title></title>
</head>
<body>
<?php
$server = mysql_connect("localhost","root", "");
$db = mysql_select_db("MyDatabase",$server);
$query = mysql_query("SELECT first_name, last_name, sign_date FROM Table1 WHERE sign_date = NOW()");
?>
<table class="striped">
<tr class="header">
<td>first_name</td>
<td>last_name</td>
<td>sign_date</td>
</tr>
<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row[first_name]."</td>";
echo "<td>".$row[last_name]."</td>";
echo "<td>".$row[sign_date]."</td>";
echo "</tr>";
}
?>
</table>
<?php
$server = mysql_connect("localhost","root", "");
$db = mysql_select_db("MyDatabase",$server);
$query = mysql_query("SELECT employee_id, job_title, address FROM Table1 WHERE sign_date = NOW()");
?>
<table class="striped">
<tr class="header">
<td>employee_id</td>
<td>job_title</td>
<td>address</td>
</tr>
<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row[employee_id]."</td>";
echo "<td>".$row[job_title]."</td>";
echo "<td>".$row[address]."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
How can the two simply be added together. The PHP does not seem to be read and is ignored when combining the two, what is the most effective way of having the two scripts work together?
You can likely combine the two parts like this - the PHP code needs to run before the mail is sent ( I found the "but when adding the following, the PHP does not work" a little confusing )
<?php
$server = mysql_connect("localhost","root", "");
$db = mysql_select_db("MyDatabase",$server);
$to = 'example#testing';
$subject = 'Testing';
$from = 'test#email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message="
<html>
<head>
<title></title>
<style>
tr.header { font-weight:bold; }
tr.alt { background-color: #777777; }
tr:nth-of-type(even) td{background-color:#777777}
</style>
</head>
<body>
<table class='striped'>
<tr class='header'>
<td>first_name</td>
<td>last_name</td>
<td>sign_date</td>
</tr>";
$query = mysql_query('SELECT first_name, last_name, sign_date FROM Table1 WHERE sign_date = NOW()');
while ( $row = mysql_fetch_array( $query ) ) {
$message.='
<tr>
<td>'.$row['first_name'].'</td>
<td>'.$row['last_name'].'</td>
<td>'.$row['sign_date'].'</td>
</tr>';
}
$message.="
</table>
<table class='striped'>
<tr class='header'>
<td>employee_id</td>
<td>job_title</td>
<td>address</td>
</tr>";
$query = mysql_query('SELECT employee_id, job_title, address FROM Table1 WHERE sign_date = NOW()');
while ($row = mysql_fetch_array($query)) {
$message.='
<tr>
<td>'.$row[employee_id].'</td>
<td>'.$row[job_title].'</td>
<td>'.$row[address].'</td>
</tr>';
}
$message.="
</table>
</body>
</html>
";
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
When you add the HTML to the body it becomes a string.
A string can convert php variables to strings. But can't execute php code.
You'll have to execute the PHP code in advance. Add the data from the PHP code to the HTML and then add the HTML to the message body.
EDIT:
This is an example of how it would work:
<?php
$html = generateHTML();
$to = 'example#testing';
$subject = 'Testing';
$from = 'test#email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = $html;
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
function generateHTML(){
$html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script><style type="text/css">tr.header{font-weight:bold;}tr.alt{background-color: #777777;}</style><script type="text/javascript">$(document).ready(function(){$(".striped tr:even").addClass("alt");});</script><title></title></head><body><table class="striped"><tr class="header"><td>first_name</td><td>last_name</td><td>sign_date</td></tr>';
$server = mysql_connect("localhost","root", "");
$db = mysql_select_db("MyDatabase",$server);
$query = mysql_query("SELECT first_name, last_name, sign_date FROM Table1 WHERE sign_date = NOW()");
while ($row = mysql_fetch_array($query)) {
$html.="<tr>";
$html.="<td>".$row[first_name]."</td>";
$html.="<td>".$row[last_name]."</td>";
$html.="<td>".$row[sign_date]."</td>";
$html.="</tr>";
}
$html.='</table><table class="striped"><tr class="header"><td>employee_id</td>td>job_title</td><td>address</td></tr>';
$server = mysql_connect("localhost","root", "");
$db = mysql_select_db("MyDatabase",$server);
$query = mysql_query("SELECT employee_id, job_title, address FROM Table1 WHERE sign_date = NOW()");
while ($row = mysql_fetch_array($query)) {
$html.="<tr>";
$html.="<td>".$row[employee_id]."</td>";
$html.="<td>".$row[job_title]."</td>";
$html.="<td>".$row[address]."</td>";
$html.="</tr>";
}
$html.= '</table></body></html>';
return $html;
}
?>
The HTML consists of simple input fields as listed in the php below, what happens is PHP mail() sends the email but excludes the form data itself. I have spent a lot of time but not sure why this is happening.
and the php to send the mail:
<?php
$to = "user#gmail.com";
$subject = "Question Bank - New Question";
$message = '<html>
<head>
<title>New Question</title>
<style>
table {
border: 1px solid black;
}
table th, tr{
text-align:center;
}
</style>
</head>
<body>
<table cellspacing="20px">
<tr>
<th>Username</th>
<th>Email</th>
<th>Question</th>
<th>Question Hint</th>
<th>Correct Answer</th>
</tr>
<tr>
<td>'.$_POST["username"].'</td>
<td>'.$_POST["email"].'</td>
<td>'.$_POST["question"].'</td>
<td>'.$_POST["questionhint"].'</td>
<td>'.$_POST["answer"].'</td>
</tr>
</table>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: user#company.com' . "\r\n";
$headers .= 'Cc: cc#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
When I try to send my mail via php, GMail does not accept my html:
Simple example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf">
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;">
<tr>
<td width="640" align="center" valign="top">
Screenshot: <img src="data:image/jpeg;base64,someimginfo" />
</td>
</tr>
</table>
</body>
</html>
GMail output:
Gmail edits my text e.g. <html> --> "<html>"
The headers I use: MIME-Version: 1.0 & Content-type: text/html; charset=UTF-8
What am I doing wrong?
EDIT PHP Code:
<?php
$recipient = "xxxxxx#gmail.com";
$image = $_POST["image"];
$contact = $_POST["contact"];
$token = $_POST["token"];
if($token != "***"){
exit('{"success":false, "error":"Invalid Token"}');
}
$from = (filter_var($contact, FILTER_VALIDATE_EMAIL)) ? $contact : 'no- reply#example.com';
$header = 'From: webmaster#example.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$txt = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="padding:0px; margin:0PX;" bgcolor="#dfdfdf">
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" bgcolor="" style="table-layout:fixed; margin:0 auto;">
<tr>
<td width="640" align="center" valign="top">
Screenshot: <img src="data:image/jpeg;base64,' . $image . '" />
</td>
</tr>
</table>
</body>
</html>
';
if(mail($recipient, "APP Support request", $txt, $header)){
exit('{"success":true}');
}
exit('{"success":false, "image":"' . $image . '"}');
?>
PHPmailer is the best class for the job!
https://github.com/PHPMailer/PHPMailer
Edit: replaced http://phpmailer.worxware.com/ with the github address.
It looks like the problem is in these lines:
$header = 'From: webmaster#example.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// …
if(mail($recipient, "APP Support request", $txt, $header)){
You switch between the names $header and $headers. So when you add the text/html content type to the variable $headers, that isn’t affecting the $header variable that is being used to actually send the email.
You should switch all those variables to the same name, $headers.
This what I have I tried to put it in a table just like:
<table>
<tr><td>$_POST['onderwerp']</td></tr>
</table>
This is what I have it sends the mail but it's to messy:
<?php
$to = 'example#gmail.com';
$subject = 'Vraag via de website';
$message = 'Onderwerp:'. $_POST['onderwerp'].'<br /><br />'.$_POST['vraag'].'<br /><br />'.'Telefoonummer:'. $_POST['tel'].'<br /><br />'.'Email:'. $_POST['email'] ;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:<eexample#gmail.com>' . "\r\n";
$headers .= 'The shop<example#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
header('Location: contact.html');
?>
I just want to send the variables in a table so that I don't have to search through all the text.
<?php
$to = 'user#example.com';
$subject = 'Vraag via de website';
$msg = "<html>
<head>
<title>Title of email</title>
</head>
<body>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">
<tr>
<td align=\"center\">Onderwerp</td>
<td align=\"center\"> vraag</td>
<td align=\"center\">Telefoonummer</td>
<td align=\"center\">Email</td>
</tr>
<tr>
<td align=\"center\">".$_POST['onderwerp']."</td>
<td align=\"center\">".$_POST['vraag']."</td>
<td align=\"center\">".$_POST['tel']."</td>
<td align=\"center\">".$_POST['email']."</td>
</tr>
</table>
</body>
</html>";
// Make sure to escape quotes
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <me#mysite.com>' . "\r\n";
mail($to, $subject, $msg, $headers);
?>
you could try this using your variables.
$var = 'test';
$var2 = 'test2';
echo '<table border="1">';
echo '<tr><td>' . $var . '</td></tr>';
echo '<tr><td>' . $var . '</td></tr>';
echo '</table>';
this will show the variables in a table, then you can edit the table using css how you want. :)
I suggest that you include swiftmailer.
Swiftmailer makes sure emails get delivered in the Inbox and you can easily include HTML markup in your emails:
Swiftmailer HTML in email
Just download the Swiftmailer Library, include and configure it like this example:
Sending an email in swiftmailer
Let me know if this helps you out!
First thing. My code works. I have my SMTP information set up correctly in IIS7's sendmail.ini, and i'm using gmail. What I have is a shopping cart for ordering food.
In my cart.php page, I have the print output pulling in the users choices:
$printoutput .= "<table width='500' border='0' cellspacing='0' cellpadding='0'>
<tr><td> <strong>Order Item # ". ($i+1) ."</strong></td></tr>
<tr><td> ". $product_name . "</td></tr>
<tr><td>$" . $price . ".00</td></tr>
<tr><td>". $displayoptions . "</td></tr></table>
<table height='1%' width='500' border='0' cellspacing='0' cellpadding='0'><tr><td></td></tr></table>";
$i++;
This output looks perfect in a web browser. Later in the code, I use a form to post the $printoutput and name it order. But on my email.php page, I use
session_start();
if(isset($_POST['order'])){
$order = $_POST['order'];
}
and then
mail($email_to, $email_subject, $order, $headers);
well like I said, I can just simply echo $order and it looks perfect in the web browser. But when actually sent as an email, I get an email with ALL of the html mark up with it. I've tried a few things, but nothing is formatting my information the way I want it to. Does anyone know how I can get this to basically format correctly in an email?
I'd like to have my information simply listed like this:
Order Item #
Product Name
Price
Options
But currently the output in the email has a ton of extra spaces, and shows all the HTML.
Any help would be appreciated.
http://www.w3schools.com/Php/func_mail_mail.asp
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// 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);
?>