Reputation: 11
At the moment when the form is submitted it sends an email that has almost no organization, for instance:
Name:
JohnDoe
email:
[email protected]
message:
blah, blah, blah
I'd like the label left aligned and the value right aligned as well as adding a background image to the email. I know I'm going to need to use tables; but I'm in no way proficient enough in PHP. Looking at the code I believe this strip has to do with the appearance. I got the form from html-form-guide.com. Any help would be greatly appreciated, thank you.
function FormSubmissionToMail()
{
$ret_str='';
foreach($_POST as $key=>$value)
{
if(!$this->IsInternalVariable($key))
{
$value = htmlentities($value,ENT_QUOTES,"UTF-8");
$value = nl2br($value);
$key = ucfirst($key);
$ret_str .= "<div class='label'>$key :</div><div class='value'>$value </div>\n";
}
}
foreach($this->fileupload_fields as $upload_field)
{
$field_name = $upload_field["name"];
if(!$this->IsFileUploaded($field_name))
{
continue;
}
$filename = basename($_FILES[$field_name]['name']);
$ret_str .= "<div class='label'>File upload '$field_name' :</div><div class='value'>$filename </div>\n";
}
return $ret_str;
}
function GetMailStyle()
{
$retstr = "\n<style>".
"body,.label, { font-family:Arial,Verdana; } ".
".label {font-weight:bold; margin-top:5px; font-size:1em; color:#000;} ".
".value {margin-bottom:15px;font-size:0.8em;padding-left:5px; font-family:Helvetica;} ".
"</style>\n";
return $retstr;
}
function GetHTMLHeaderPart()
{
$retstr = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".
'<html><head><title></title>'.
'<meta http-equiv=Content-Type content="text/html; charset=utf-8">';
$retstr .= $this->GetMailStyle();
$retstr .= '</head><body>';
return $retstr;
}
function GetHTMLFooterPart()
{
$retstr ='</body></html>';
return $retstr ;
}
function ComposeFormtoEmail()
{
$header = $this->GetHTMLHeaderPart();
$formsubmission = $this->FormSubmissionToMail();
$footer = $this->GetHTMLFooterPart();
$message = $header."Submission from 'contact us' form:<p>$formsubmission</p><hr/>".$footer;
return $message;
}
Upvotes: 0
Views: 254
Reputation: 2032
if you only need to send email, it better make html.inc and import this with
require(html.inc)
put the variable in the file and after send the email wiht phpmailer.
use this to html.inc
Upvotes: 0
Reputation: 362
CSS support really varies in different email clients. Your code is loading the CSS in <style>
tags, in the head
tag. This is only supported in some email clients, so some will not load any of the CSS at all.
I've found the most widely supported method of including CSS is using style
attributes on each individual HTML element (yes this is a pain to do). Also, not all css rules are supported. A handy guide for which email client supports what can be found here.
Also, make sure that you are using the correct email headers for sending HTML emails with PHP's mail function. See example #4.
Upvotes: 2