Text direction and alignment in email sent via email() using PHP - php

I am sending an automatic email via php. The email contains Hebrew which direction is right to left. Here is my code for making up the body part of the message:
$emailMessage ='
<html lang="HE">
<head>
<title>
job-skills | הצורפות
</title>
</head>
<body style="text-align:right; direction:rtl;">
<table>
<tr>
<td><h3>תודה על הצטרפותך</h4></td>
</tr>
<tr>
<td>על מנת להצטרף סופית לאתר עליך ללחץ על הלינק הבא:</td>
</tr>
<tr>
<td><a href="http://localhost/W-DB/php/registration_and_login/confirm_registration.php?email=' .$registrationEmail .'&tempPass=' . $tempPass . '>לחץ כאן</a></td>
<tr>
</tr>
<tr>
<td>בברכה,</td>
</tr>
<tr>
<td><h2>JOb-Skills</h2></td>
</tr
</table>
</body>
</html>
still the text aligned to left and direction left to right.

Here is my code:
<?php
$to ="mail id";
$from = "mail id";
$sub = "Hebrew";
$message = '<html lang="HE">
<head>
<title>
job-skills | הצורפות
</title>
</head>
<body style="text-align:right; direction:rtl;">
<table>
<tr>
<td><h3>תודה על הצטרפותך</h4></td>
</tr>
<tr>
<td>על מנת להצטרף סופית לאתר עליך ללחץ על הלינק הבא:</td>
</tr>
<tr>
<td>
לחץ כאן</td>
<tr>
</tr>
<tr>
<td>בברכה,</td>
</tr>
<tr>
<td><h2>JOb-Skills</h2></td>
</tr
</table>
</body>
</html>';
$headers = "From:" . $from;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
if(mail($to,$sub,$message,$headers)) echo "success";
?>

Try adding dir="rtl" to your HTML tag.

Please refer to style #Varun placed in the body: <body style="text-align:right; direction:rtl;">
Only after I added this style to the body it worked also on gmail, until then It was working only on Outlook.

It is working fine with the code I mentioned. Please have a look to the attached image.

Related

PHP mail send very slowly

I have a VPS with inmotion hosting, and i send a confirmation email, but the email it takes too mucho to send, how is the best way to estructure the html code when i send a mail, how can i boost the performance.
This is my code.
$subject = 'Mail activation';
$body = '
<html>
<head>
<base target="_blank">
</head>
<body>
<table style="max-width:800px; margin:0 auto; font-family: Arial, Helvetica, sans-serif;" cellspacing="0" cellpadding="10">
<thead style="border-bottom:1px solid #DDD;">
<tr>
<td align="center" style="border-bottom:1px solid #DDD;">
<img src="http://p.unid.com/img/logoSASENegro.png" alt="" height="45" width="150"/>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
Hi classmate
</td>
</tr>
<tr>
<td>
Press the following link.
</td>
</tr>
<tr>
<td>
www.google.com
</td>
</tr>
<tr>
<td>
You data:
</td>
</tr>
<tr>
<td>
ID - <b>'.$ids.'</b><br/>
Password - <b>'.$pass.'</b><br/>
</td>
</tr>
<tr>
<td>
Don't response this email.
</td>
</tr>
</tbody>
</table>
</body>
</html>
';
$headers = "MIME-Version: 1.0\r\n";
$headers .="Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: Contacto SASE <atencionsase#unid.mx>\r\n";
if(mail($emailC, $subject, $body, $headers))
On some servers mail() sent emails really slow. Your issue is not related to message content, but it related to your hosting provider. As a possible solution, you can just switch your script to sending mail via different SMTP server (for example gmail: Send email using the GMail SMTP server from a PHP page).

How to send email include html code using php? [duplicate]

This question already has an answer here:
How to send mail using php by insert html into mail content? [duplicate]
(1 answer)
Closed 7 years ago.
How to send email include html code using php ?
I tried to use this code.
<?PHP
include("connect.php");
$email = "test_mail#hotmail.com";
$to = $email;
$subject = "test subject";
$message = "
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply#example.com>' . "\r\n";
$headers .= 'Return-Path: return#example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#example.com');
?>
When i open my email it's will show like this in my email.
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
But i want to show like this
How can i do ?
........................................................................................................................................................
Reason being is, that you don't have <!doctype html> and </html> tags (and other tags) and your HTML isn't being rendered as proper/full HTML markup.
$message = "
<!doctype html>
<html>
<head>
<title></title>
</head>
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
</html>
";
Which upon testing afterwards, was successful.
Foonotes: (edit)
Even though I placed an answer, I decided to close the question being an exact duplicate of their other question How to send mail using php by insert html into mail content? where they were also nonrespondant and the answer given in there, answered what they posted for code.

PHP Mail not showing HTML in Switch Statement

I have a form with all the submissions going to one person but also sends a copy to another person responsible for the State that the user chose with the switch statement. The notification email that goes the the main admin looks fine (html is generated) but the ones in the switch statement are showing as plain text and show the HTML tags. Any idea how to fix this? Thank you.
//after user registers send notification to admin
$to = 'admin#email.com'
$subject = 'subject';
$message = "<!DOCTYPE html>
<html>
<body>
<div align='left'>
<strong>New Registration Information:</strong><br />
<br />
<table cellspacing=\"4\" cellpadding=\"4\" align=\"left\">
<tr>
<td><strong>Username:</strong></td>
<td>".$userInput."</td>
</tr>
<tr>
<td><strong>Password:</strong></td>
<td>".$passInput."</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td>".$emailInput."</td>
</tr>
<tr>
<td><strong>First Name:</strong></td>
<td> ".$fnameInput."</td>
</tr>
<tr>
<td><strong>Middle Name:</strong></td>
<td>".$mnameInput."</td>
</tr>
<tr>
<td><strong>Last Name:</strong></td>
<td>".$lnameInput."</td>
</tr>
<tr>
<td><strong>Job Title:</strong></td>
<td>".$jobtitleInput."</td>
</tr>
<tr>
<td><strong>Company</strong></td>
<td>".$companyInput."</td>
</tr>
<tr>
<td><strong>Address:</strong></td>
<td>".$addressInput."</td>
</tr>
<tr>
<td><strong>City:</strong></td>
<td>".$cityInput."</td>
</tr>
<tr>
<td><strong>State:</strong></td>
<td>".$stateInput."</td>
</tr>
<tr>
<td><strong>Zip:</strong></td>
<td>".$zipInput."</td>
</tr>
<tr>
<td><strong>Phone Number:</strong></td>
<td>".$phoneInput."</td>
</tr>
<tr>
<td><strong>Registered State:</strong></td>
<td>".$registeredstateInput."</td>
</tr>
<tr>
<td><strong>Membership Level:</strong></td><td>";
if($membershipLevel == 1)
$message .= "Level 1 Here</td></tr></table></div></html>";
else if($membershipLevel == 2)
$message .= "Level 2 Here</td></tr></div></html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
//now send email to State contact
switch($registeredstateInput){
case "AZ":
$to = 'emailaddress1#email.com';
break;
case "AR":
$to = 'emailaddress2#email.com';
break;
case "CA":
$to = 'emailaddress3#email.com';
break;
}
//if that state doesn't have a contact, don't send email
if($to != 'admin#email.com')
{
mail($to, $subject, $message);
}

PHP MAILER, HOW TO INSERT HTML TABLE

I have PHP mailer script and I am trying to add HTML table into it but when I do the script stops working.
Here's the PHP mailer script
<?php
// Insert your email/web addresses and correct paths
$mailto = 'adil#*******.co.uk' ;
$from = "web#city.com" ;
$subject = "Query from ******* 2012";
$headers = "From: ******* Website";
$formurl = "http://*******.co.uk/citycoaches3/formmail.php" ;
$errorurl = "http://*******.co.uk/citycoaches3/error.php" ;
$thankyouurl = "http://*******.co.uk/citycoaches3/thankyou.php" ;
// Place Your Form info here...
$pickuppoint = ($_POST['pickuppoint']);
$destination = ($_POST['destination']);
// Check If Empty
// Add more Validation/Cleaning here...
// Place your Corresponding info here...
$message =
"Pick Point: $pickuppoint\n\n" .
"Destination: $destination\n\n" .
"noppl: $noppl\n\n"
;
// Leave Alone
mail($mailto, $from, $message);
header( "Location: $thankyouurl" );
exit ;
?>
Any help on this will be appreciated.
Heres what i tried
<?php
$fromAddr = 'adil#********.co.uk'; // the address to show in From field.
$recipientAddr = 'quotes#********.co.uk';
$subjectStr = '[Quick] Query From ********';
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$forward = 1;
$formurl = "http://www.********.co.uk/formmail.php" ;
$errorurl = "http://www.********.co.uk/error.php" ;
$thankyouurl = "http://www.********.co.uk/thankyou.php" ;
header("location:thankyou.php");
$mailBodyText = <<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Thank You</title>
</head>
<body>
<img src="http://********.co.uk/images/mailsig.png" /> \n\n<br />
<span style="color:#900; font-size:18px;">Below is the result submitted from <strong>[Quick Quote] ******** Website</strong>. It was submitted on <strong>$date at $time</strong>.\n\n</span>
<p><table width="600" border="1" cellpadding="5px">
<tr>
<td><b>Pickup Date:</b> </td>
<td>{$_POST['date']}<br></td>
</tr>
<tr>
<td><b>Pickup Time:</b> </td>
<td>{$_POST['PickupTime-Hours']}:{$_POST['PickupTime-Mins']}<br></td>
</tr>
<tr>
<td><b>Pickup Point:</b> </td>
<td>{$_POST['PickUp-Point']}<br></td>
</tr>
<tr>
<td><b>Destination:</b> </td>
<td>{$_POST['Destination']}<br></td></tr>
<tr>
<td><b>No. Of People:</b> </td>
<td>{$_POST['No-of-Persons']}<br></td>
</tr>
<tr>
<td><b>Journey Type:</b> </td>
<td>{$_POST['JourneyType']}<br></td>
</tr>
<tr>
<tr>
<td><b>Return Date:</b> </td>
<td>{$_POST['returnDate']}<br></td>
</tr>
<tr>
<td><b>Return Time:</b> </td>
<td>{$_POST['returnTime-Hours']}{$_POST['returnTime-Mins']}<br></td>
</tr>
<tr>
<tr>
<td><b>Vehicle Type:</b> </td>
<td>{$_POST['type']}<br></td>
</tr>
<tr>
<tr>
<td><b>Full Name:</b> </td>
<td>{$_POST['Full-Name']}<br></td>
</tr>
<tr>
<tr>
<td><b>Tel / Mobile:</b> </td>
<td>{$_POST['Tel-Mobile']}<br></td>
</tr>
<tr>
<td><b>Email:</b> </td>
<td>{$_POST['Email']}<br></td>
</tr>
<tr>
</table>
</p>
</body>
</html>
HHHHHHHHHHHHHH;
$headers= <<<TTTTTTTTTTTT
From: $fromAddr
MIME-Version: 1.0
Content-Type: text/html;
TTTTTTTTTTTT;
mail($mailto, $from, $message,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
header( "Location: $thankyouurl" );
exit ;
?>
Still doesn't work for some reason.
Heres the UPDATE:
After removing
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
I managed to receive the email, but it pasted the whole code which is in $message.
Try getting the HTML from a file :
$message = file_get_contents('./path/email.html') // it's easyer to maintain but not mandatory
And add a html content type header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
then
mail($mailto, $from, $message, $headers) //notice the headers;
As I think the others answers didn't gave you the correct direction yet, here's my addition:
$name = _("test"); // Or insert variable
$message = <<<EOF
// html here
<p>hello $name</p>
EOF;
$to = "";
$subject = "";
// 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 .= 'From: Example <info#example.com>' . "\r\n";
// Mail it
mail($to, $subject, $email, $headers);
You'll need the html headers when sending the email..
ALL thank you very much for your help and suggestions.
I finally got it working here is what I did.
In $message in inserted:
$message = "<html><body>
<b><FONT COLOR='#900' SIZE='13px'>Hi this is working now</FONT></b>
<table width='400' border='0' cellpadding='5px'>
<tr>
<td><b><FONT COLOR='#900'>Pickup Date:</FONT></b> </td>
<td>{$_POST['date']}<br></td>
</tr>
</table>
</html></body>";
And added following headers
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
All working thanks everyone again!
Use php html email and insert table in email body part
If you want to display the messagebody in your message to your recipient, maybe you should try putting a quotation mark in your code:
$mailBodyText = "<<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Thank You</title>
</head>
<body>
<img src="http://********.co.uk/images/mailsig.png" /> \n\n<br />
<span style="color:#900; font-size:18px;">Below is the result submitted from <strong> [Quick Quote] ******** Website</strong>. It was submitted on <strong>$date at $time</strong>.\n\n</span>
<p><table width="600" border="1" cellpadding="5px">
<tr>
<td><b>Pickup Date:</b> </td>
<td>{$_POST['date']}<br></td>
</tr>
<tr>
<td><b>Pickup Time:</b> </td>
<td>{$_POST['PickupTime-Hours']}:{$_POST['PickupTime-Mins']}<br></td>
</tr>
<tr>
<td><b>Pickup Point:</b> </td>
<td>{$_POST['PickUp-Point']}<br></td>
</tr>
<tr>
<td><b>Destination:</b> </td>
<td>{$_POST['Destination']}<br></td></tr>
<tr>
<td><b>No. Of People:</b> </td>
<td>{$_POST['No-of-Persons']}<br></td>
</tr>
<tr>
<td><b>Journey Type:</b> </td>
<td>{$_POST['JourneyType']}<br></td>
</tr>
<tr>
<tr>
<td><b>Return Date:</b> </td>
<td>{$_POST['returnDate']}<br></td>
</tr>
<tr>
<td><b>Return Time:</b> </td>
<td>{$_POST['returnTime-Hours']}{$_POST['returnTime-Mins']}<br></td>
</tr>
<tr>
<tr>
<td><b>Vehicle Type:</b> </td>
<td>{$_POST['type']}<br></td>
</tr>
<tr>
<tr>
<td><b>Full Name:</b> </td>
<td>{$_POST['Full-Name']}<br></td>
</tr>
<tr>
<tr>
<td><b>Tel / Mobile:</b> </td>
<td>{$_POST['Tel-Mobile']}<br></td>
</tr>
<tr>
<td><b>Email:</b> </td>
<td>{$_POST['Email']}<br></td>
</tr>
<tr>
</table>";

Mail() php is sending the code direct in the mail [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Php mail: how to send html?
I got my mail() with php working my emailmessage =
$email_bericht .= "
<table border='0' width='40%'>
<tr>
<td>Bedrijfsnaam</td>
<td>
".$naam."
</td>
</tr>
<tr>
<td>Risicoadres</td>
<td>
".$risicoadres."
</td>
</tr>
<tr>
<td>Adres</td>
<td>
".$adres."
</td>
</tr>
<tr>
<td>Woonplaats</td>
<td>
".$woonplaats."
</td>
</tr>
<tr>
<td>Relatienummer</td>
<td>
".$relatienummer."
</td>
</tr>
<tr>
<td>Aanhef</td>
<td>
".$aanhef."
</td>
</tr>
<tr>
<td>Contactpersoon</td>
<td>
".$contactpersoon."
</td>
</tr>
<tr>
<td>mailadres</td>
<td>
".$emailadres."
</td>
</tr>
<td>Jaar</td>
<td>
".$jaar."
</td>
</tr>
</table>";
In the email it shows :
<table border='0' width='40%'>
<tr>
<td>Bedrijfsnaam</td>
<td>
Bob
</td>
</tr>
<tr>
<td>Risicoadres</td>
<td>
Bobstreet 12
</td>
</tr>
<tr>
<td>Adres</td>
<td>
Bobstreet 12
</td>
</tr>
<tr>
<td>Woonplaats</td>
<td>
England
</td>
</tr>
<tr>
<td>Relatienummer</td>
<td>
123456
</td>
</tr>
<tr>
<td>Aanhef</td>
<td>
Dear guy
</td>
</tr>
<tr>
<td>Contactpersoon</td>
<td>
Bob
</td>
</tr>
<tr>
<td>mailadres</td>
<td>
BOB#bobbv.nl
</td>
</tr>
<td>Jaar</td>
<td>
2028
</td>
</tr>
</table>";
My mail() =
mail($email_naar, $email_onderwerp, $email_bericht);
mail($emailadres, $email_onderwerp, $email_bericht);
It shows all the table/tr's/td's etc in the mail that has been send to the email adress any way to solve this problem do i need to use a html tag or something?
if send mail without header information it will take table,tr,td as string
you need to in include
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '. $sendermail . "\r\n";
mail($to, $subject, $message, $headers)
You need to set
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
And then:
mail($email_naar, $email_onderwerp, $email_bericht, $headers);
You need to add headers to your mail() call (fourth parameter)
Specifically for your purpose you need (with relevant charset)
'Content-type: text/html; charset=iso-8859-1';
Please, refer to http://php.net/manual/en/function.mail.php to learn more about sending headers in e-mail. You'll need some of them, like 'Reply-To' and some others
I think mail() function sending mail as a plain text where HTML part will not be rendered.
Here is the sample program to send HTML email. (copy and paste from php.net)
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
Code source from http://php.net/manual/en/function.mail.php

Categories