Jump to content

mail form


JDest

Recommended Posts

I have some code for a mail form and it works fine except the email doesn't actually get sent. It progresses to the success page but the email isn't delivered. I can't figure it out! Anybody have any ideas?

 

 

<?php
/*
Template for form to email
*/
session_start();
if((isset($_POST["form-complete"])) && ($_POST["form-complete"] == "form-complete") && $_POST['secure'] == $_SESSION['security_number'])
{

//create mail variables
$to = "[email protected]";
$toAlso = "[email protected]";
$fromName = $_POST['full_name'];
$fromEmail = $_POST['email_address'];
$subject = $_POST["subject"];

$emailHeaders = "MIME-Version: 1.0\r\n";
$emailHeaders .= "Content-type: text/html; charset-ISO-8859-1\r\n";
$emailHeaders .= "From: " . $fromName . " <" . $fromEmail . ">\r\n";
$message = "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" style=\"font-size:11px;\">";
$redirect_success = get_permalink(699);
$redirect_error = get_permalink(715);
define('REDIRECT_SUCCESS', $redirect_success);
define('REDIRECT_ERROR', $redirect_error);
//$redirectSuccess = "/?page_id=650";
//$redirectError = "/?page_id=648";
$counter = 2;
$tripCounter = 0;
$attachments;
$uid = md5(uniqid(time()));
$path = "test/upload/";
//seperates form name into usable fields
//removes "record" from begining of input name
//seperates words by capitol letter and number
function mail_attachment($mailto, $from_mail, $from_name, $subject, $message2, $mailattachments, $uid2)
{
 $name = basename($file);
 $header = 'To: '.$mailto.' <'.$mailto.'>' . "\r\n";
 //$header = 'To: '.get('contact_list_email_address_name', ($_POST['emailed_to']), 1, 1, 194).' <'.$mailto.'>' . "\r\n";
 $header .= "From: ".$from_name." <".$from_mail.">\r\n";
 //if(getFieldOrder('cc_email_address',1, 194))
 {
  //for($i=0;$i<sizeof(getFieldOrder('cc_email_address',1, 194));$i++)
  {
   //$header .= 'Cc: ' . get_field_duplicate('cc_email_address', 1, ($i+1), 1, 194) . "\r\n";
  } 
 }
 $header .= "MIME-Version: 1.0\r\n";
 $header .= "Content-Type: multipart/mixed; boundary=\"".$uid2."\"\r\n\r\n";
 $header .= "This is a multi-part message in MIME format.\r\n";
 $header .= "--".$uid2."\r\n";
 $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
 $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
 $header .= $message2."\r\n\r\n";
 $header .= $mailattachments;
 $header .= "--".$uid2."--";
 if (mail($mailto, $subject, "", $header))
 {
  unset($_POST);
  unset($_FILES);
  //header("Location: " . REDIRECT_SUCCESS);  // redirect on success
  echo $message2;
 } else
 {
  unset($_POST);
  unset($_FILES);
  //header("Location: " . REDIRECT_ERROR);  // redirect on success
 }
}
function cleanLabel($tempLabel)
{
 $search = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0");  // if using Caps and numbers as seperators
 $seperator = "_";  // if using underscore as word seperator
 $tempLabel = str_replace("record", "", $tempLabel);  //removes record from begining of input names
 $serchLength = count($search);
 $tempLabel[0] = str_replace($tempLabel[0], strtoupper($tempLabel[0]), $tempLabel[0]);
 for($i=0;$i<$serchLength;$i++)
 {
  $tempLabel = str_replace(("_" . strtolower($search[$i])), (" " . strtoupper($search[$i])), $tempLabel);  // removes search variable and replaces with a space
 }
 return $tempLabel;
}
function cleanValue($tempValue)
{
 // strips HTML from values and replaces new line escape sequence with <br />
 $tempValue = strip_tags($tempValue);
 $tempValue = str_replace("\n", "<br />", $tempValue);
 if($tempValue == "(choose one)")
  $tempValue = "";
 return $tempValue;
}
//break post arrays into key / value pairs
foreach($_POST as $key => $value)
{
 if($counter % 1 == 0)
 {
  $tagBefore = "<tr>";
  $tagAfter = "";
 }
 else
 {
  $tagBefore = "";
  $tagAfter = "</tr>";
 }
 if(!is_array($value))
  if((substr($key, 0, 5) == "phone") || (substr($key, 0, 3) == "fax"))
  {
   if(!$tripCounter)
   {
 if(substr($key, 0, 5) == "phone")
  $message .= "<tr><td style=\"text-align:right\"><strong>Phone Number:</strong></td><td>" . cleanValue($value);
 if(substr($key, 0, 3) == "fax")
  $message .= "<tr><td style=\"text-align:right\"><strong>Fax Number:</strong></td><td>" . cleanValue($value);
 $tripCounter++;
   }
   else if($tripCounter==1)
   {
 $message .= "-" . cleanValue($value);
 $tripCounter++;
   }
   else if($tripCounter==2)
   {
 $message .= "-" . cleanValue($value) . "</td></tr>";
 $tripCounter=0;
   }
  }
  else if(substr($key, 0, 17) == "heading_for_email")
   $message .= "<tr><td> </td></tr><tr><td style=\"text-align:right\"></td><td style=\"text-align:left\"><strong>" . cleanValue($value) . "</strong></td></tr>";
  else if($key != "submit" && $key != "form-complete" && $key != "secure" && $key != "emailed_to" && $key != "submit_x" && $key != "submit_y")
   $message .= $tagBefore . "<td style=\"text-align:right\"><strong>" . cleanLabel($key) . ":</strong></td><td style=\"text-align:left\">" . cleanValue($value) . "</td>" . $tagAfter;
 // if values is array - break into key2 / value2 pairs
 if(is_array($value))
 {
  $message .= $tagBefore . "<td style=\"text-align:right; vertical-align:top\"><strong>" . cleanLabel($key) . ":</strong></td><td style=\"text-align:left\">";
  foreach($value as $key2 => $value2)
  {
   echo $key2;
   $message .= cleanValue($value2) . "<br />";
  }
  $message .= "</td>" . $tagAfter;
 }
 $counter++;
}
$message .= "</table>";
//echo $message;
if(mail($to, $subject, $message, $emailHeaders))  // send mail
{
 mail($toAlso, $subject, $message, $emailHeaders);
 header("Location: " . $redirect_success);  // redirect on success
}
else
{
 header("Location: " . $redirect_error);  // redirect on error
}
}
else if((isset($_POST["form-complete"])) && ($_POST["form-complete"] == "form-complete") && $_POST['secure'] != $_SESSION['security_number'])
{
//header("Location: " . $_SERVER["HTTP_REFERER"]);  // redirect on success
$userMessage = '<div id="user_message_area" class="user_message_box white_round"><span class="user_message">There was an error sending your message.<br />Please <a href="#" onclick="hide_box(\'user_message_area\');">try again.</a></span></div>';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/274705-mail-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.