[SOLVED] New problem created trying to fix original
Posted: Tue Jun 03, 2008 4:04 pm
Now I have a new issue, as a result of trying to remedy my original form problem. All I'm trying to do is send a simple form. Error: Warning: Cannot modify header information - headers already sent by (output started at /home/bullzico/public_html/support_handler.php:8) in /home/bullzico/public_html/support_handler.php on line 77
All I'm trying to do is figure out how to write lines 64 and 65 that sends my form data.
All I'm trying to do is figure out how to write lines 64 and 65 that sends my form data.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["name"]) || empty($_POST["email"]) || empty($_POST["organization"]) || empty($_POST["phone"]))
{
//redirect back to form
header("Location: support.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["name"];
$organization = $_POST["organization"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$fax = $_POST["fax"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$body = $_POST["comments"];
//Validate the email address using a regex
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email))
{
header("Location: /support.php?error=invalid_email");
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: /support.php?error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "bullzi_swift/Swift.php";
require_once "bullzi_swift/Swift/Connection/Sendmail.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Try to connect using /usr/sbin/sendmail -bs
$swift =& new Swift(new Swift_Connection_Sendmail());
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("Bullzi Support Request from:" . $organization);
$message->attach(new Swift_Message_Part($name, $phone, $email, $fax, $address, $city, $state, $zip, $body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, "me@mysite.tld", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: /thanks.html");
exit();
}
else
{
header("Location: /support.php?error=sending_failed");
exit();
}
?>
</body>
</html>