General Question

Editor08's avatar

Server issue or PHP? - Contact Form Not Sending HTML correctly?

Asked by Editor08 (1points) October 3rd, 2009

I am using the following code which is being sent over SMTP. When email message is received in gmail raw html appears. In Outlook the message is blank. What is the issue? A php error or server problem?

(process-form.php)
<!DOCTYPE HTML PUBLIC ”-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859–1”>
<style>
body {
background-color: #6BBDB9;
}
div {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
div.mailbody {
font-family: “Courier New”, Courier, mono;
}
div.mailfail {
width: 450px;
border: 3px solid #000000;
padding: 22px 22px 22px 22px;
text-align: center;
vertical-align: middle;
background-color: #FEBA3B;
color: #3F2401;
font-weight: bold;
}
div.mailsent {
width: 450px;
border: 3px solid #000000;
padding: 22px 22px 22px 22px;
text-align: center;
vertical-align: middle;
background-color: #FF900B;
color: #000000;
font-weight: bold;
}
</style>
<title><?php echo($title); ?></title>
<?php

require (“smtpclass.php”);
if($_SERVER[“REQUEST_METHOD”] == “POST”)
{
$smtp=new SMTPMAIL;

$stemail = “test@gmail.com”; //EMAIL TO RECIEVE THE PRESENTATION BOOKINGS
$stsubject = “Contact from Website”; //THE SUBJECT OF THE EMAIL
$stfrom = “do-not-send@website.com”; //THE ‘From:’ EMAIL ADDRESS
$stwho= “website”; //NAME TO APPEAR ON THE EMAIL
$streply= “do-no-reply@website.com”; //THE REPLY-TO ADDRESS
$cc=””;

if(!$_POST[‘fullname’]) {
header(“Location: index.html”);
}

$headers = “From: ” .$stwho. ”<”.$stfrom. ”>\n” . “Reply-To: ” .$streply. ”\n”;
$headers .= ‘MIME-Version: 1.0’ . ”\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859–1’ . ”\r\n”;
// message
$message = ””;

$artype = array(
“keynote” => “Keynote Address”,
“seminar” => “Seminar”,
“workforce” => “Workforce Development”,
“training” => “Leadership / Staff Training”
);
$arevent = array(
“forum” => “Forum”,
“formal” => “Formal Address”,
“informal” => “Informal Address – Audience Interaction”,
“discussion” => “Discussion”,
“solving” => “Problem Solving”
);

$audtype = ””;
if($_POST[‘professional’]) { $audtype.=“Professional”; }
if($_POST[‘management’]) { $audtype.=“Management”; }
if($_POST[‘employees’]) { $audtype.=“Employees”; }
if($_POST[‘youth’]) { $audtype.=“Youth”; }
$audgend = ””;
if($_POST[‘male’]) { $audgend.=“Male”; }
if($_POST[‘female’]) { $audgend.=“Female”; }
if($_POST[‘coed’]) { $audgend = “Co-ed”; }
$ftimeframe = “Multi Day”;
if($_POST[‘timeframe’] == ‘single’) {
$ftimeframe = “Single Day”;
}
$fotherspeakers = “None”;
if($_POST[‘otherspeakers’] == ‘yes’) {
$fotherspeakers = strip_tags($_POST[‘whospeakers’]);
}
$avequip = “None”;
if($_POST[‘equip’] == ‘yes’) {
$avequip = strip_tags($_POST[‘yesequip’]);
}
$artopics = array(
“book” => “The book”,
“leadership” => “Leadership & Management”,
“communication” => “Communication”,
“planning” => “Planning”,
“skills” => “Presentation Skills”,
“contracts” => “Government Contracts”
);

$message .= ”<html><body>”;
$message .= ”\n<table rules=\“all\” style=\“border-color: #666;\” cellpadding=\“10\” width=\“100%\”>”;
$message .= ”\n<tr style=‘background: #eee;’><td width=‘30%’><strong>Name:</strong> </td><td width=‘70%’>” . strip_tags($_POST[‘fullname’]) . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Phone:</strong> </td><td>” . strip_tags($_POST[‘phone’]) . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Email:</strong> </td><td>” . strip_tags($_POST[‘email’]) . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Organization:</strong> </td><td>” . strip_tags($_POST[‘organization’]) . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Address:</strong> </td><td>” . strip_tags($_POST[‘address’]) . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Type of Presentation:</strong> </td><td>”;
if($_POST[‘type’] == “other”) {
$message .= strip_tags($_POST[‘typeother’]) . ”</td></tr>”;
} else {
$message .= $artype[$_POST[‘type’]] . ”</td></tr>”;
}
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Type of Event:</strong> </td><td>” . $arevent[$_POST[‘event’]] . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Audience Type:</strong> </td><td><ul>” . $audtype . ”</ul></td></tr>”;
if($_POST[‘youth’]) {
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Youth Age Group:</strong> </td><td>” . strip_tags($_POST[‘youthother’]) . ”</td></tr>”;
}
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Audience Gender:</strong> </td><td><ul>” . $audgend . ”</ul></td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Event Time Frame:</strong> </td><td>” . $ftimeframe . ”</td></tr>”;
if($_POST[‘timeframe’] == ‘multi’) {
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Days:</strong> </td><td>” . strip_tags($_POST[‘multidays’]) . ”</td></tr>”;
}
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Other Speakers:</strong> </td><td>” . $fotherspeakers . ”</td></tr>”;
if($fotherspeakers != ‘None’) {
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Speakers Topics:</strong> </td><td>” . strip_tags($_POST[‘speakerstopics’]) . ”</td></tr>”;
}
$message .= ”\n<tr style=‘background: #eee;’><td><strong>A/V Equipment:</strong> </td><td>” . $avequip . ”</td></tr>”;
$message .= ”\n<tr style=‘background: #eee;’><td><strong>Desired Topics:</strong> </td><td>”;
if($_POST[‘topics’] == “other”) {
$message .= strip_tags($_POST[‘topicsother’]) . ”</td></tr>”;
} else {
$message .= $artopics[$_POST[‘topics’]] . ”</td></tr>”;
}
$message .= ”\n</table>”;
$message .= ”\n</body></html>”;

if(!$smtp->send_smtp_mail($stemail,$stsubject,$message,$headers,$cc,$stfrom))

$error=“Error in sending the following message please directly email contact@website.com: ”.$smtp->error;
else
$report=“The following message was sent successfully!”;
}

?>

<?php @extract($_POST);?>
</head>

<body>

<center><div class=“mailsent”><?php echo $report; echo $error; ?>:<br /><br />
<div class=“mailbody”><?php echo($message); ?></div><br /><br />
<a href=“javascript:history.go(-1);”>Go Back</a>
</div></center>

</body>
</html>

(smtpclass.php)
<?php

class SMTPMAIL
{
var $host=””;
var $port=25;
var $error;
var $state;
var $con=null;
var $greets=””;

function SMTPMAIL()
{
$this->host=ini_get(“SMTP”);
$this->port=25;
$this->state=“DISCONNECTED”;
}
function set_host($host)
{
$this->host=$host;
}
function set_port($port=25)
{
$this->port=$port;
}
function error()
{
return $this->error;
}
function connect($host=””,$port=25)
{
if(!empty($host))
$this->host($host);
$this->port=$port;
if($this->state!=“DISCONNECTED”)
{
$this->error=“Error : connection already open.”;
return false;
}

$this->con=@fsockopen($this->host,$this->port,$errno,$errstr);
if(!$this->con)
{
$this->error=“Error($errno):$errstr”;
return false;
}
$this->state=“CONNECTED”;
$this->greets=$this->get_line();
return true;
}
function send_smtp_mail($stemail,$stsubject,$data,$headers,$cc=””,$stfrom=‘support’)
{
$ret=$this->connect();
if(!$ret)
return $ret;
$this->put_line(“MAIL FROM: $stfrom”);
$response=$this->get_line();
if(intval(strtok($response,” ”))!=250)
{
$this->error=strtok($response,”\r\n”);
return false;
}
$stemail_err=preg_split(”/[,;]/”,$stemail);
foreach($stemail_err as $mailto)
{
$this->put_line(“RCPT TO: $mailto”);
$response=$this->get_line();
if(intval(strtok($response,” ”))!=250)
{
$this->error=strtok($response,”\r\n”);
return false;
}
}
if(!empty($cc))
{
$stemail_err=preg_split(”/[,;]/”,$cc);
foreach($stemail_err as $mailto)
{
$this->put_line(“RCPT TO: $mailto”);
$response=$this->get_line();
if(intval(strtok($response,” ”))!=250)
{
$this->error=strtok($response,”\r\n”);
return false;
}
}
}
$this->put_line(“DATA”);
$response=$this->get_line();
if(intval(strtok($response,” ”))!=354)
{
$this->error=strtok($response,”\r\n”);
return false;
}
$this->put_line(“TO: $stemail”);
$this->put_line(“SUBJECT: $stsubject”);
$this->put_line($data);
$this->put_line(”.”);
$response=$this->get_line();
if(intval(strtok($response,” ”))!=250)
{
$this->error=strtok($response,”\r\n”);
return false;
}
$this->close();
return true;
}
// This function is used to get response line from server
function get_line()
{
while(!feof($this->con))
{
$line.=fgets($this->con);
if(strlen($line)>=2 && substr($line,-2)==”\r\n”)
return(substr($line,0,-2));
}
}
////This functiuon is to retrive the full response message from server

////This functiuon is to send the command to server
function put_line($msg=””)
{
return @fputs($this->con,”$msg\r\n”);
}

function close()
{
@fclose($this->con);
$this->con=null;
$this->state=“DISCONNECTED”;
}
}

?>

Observing members: 0 Composing members: 0

1 Answer

Breefield's avatar

Next time use Pastebin.
I think your problem is somehow HTML related, like a missing tag, or validation error. Try just sending a text email and build pieces bit by bit from.
Outlook and other email programs tend to be finicky in how they parse HTML, whereas Gmail (browser based to begin with), isn’t quite as finicky.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther