Page 1 of 1

[SOLVED] New problem created trying to fix original

Posted: Tue Jun 03, 2008 4:04 pm
by bullzi
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.

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>

Re: New problem created trying to fix original form problem

Posted: Tue Jun 03, 2008 4:56 pm
by Weirdan
move the html the file starts with somewhere after the header calls. Or remove it altogether - you don't need it anyway as you don't show anything to user - just redirecting him to another page.

Re: New problem created trying to fix original form problem

Posted: Tue Jun 03, 2008 6:00 pm
by bullzi
Thanks. That solved it.

Re: [SOLVED] New problem created trying to fix original

Posted: Tue Jun 03, 2008 8:42 pm
by Chris Corbyn
This is wrong:

Code: Select all

$message->attach(new Swift_Message_Part($name, $phone, $email, $fax, $address, $city, $state, $zip, $body));
Read the documentation to see what Swift_Message_Part is actually for ;)

Re: [SOLVED] New problem created trying to fix original

Posted: Wed Jun 04, 2008 10:20 am
by bullzi
I've read the documentation and API docs for 6 days and am still trying to figure out where to put multiple form fields.
I've also known that code is wrong and what swift_message_part does for 3 days. It remains, as this thread was the result of another failed experiment and I haven't figured out what to replace it with.
The "form documentation" addresses only default swift_message object data of "string" and "mixed". I have 10 fields.
Where do I put them? I've looked at parts, headers, attachments and now I'm trying to figure out where I might put an array and the proper syntax for an array.
I've had 250 viewings over 4 posts with 3 replies. 2 of the replies, both gracious, stated they don't know Swift and the third said read the documentation. If it was as simple, for a newbie, as reading the documentation I would have been finished days ago. I only post to forums after I have exhausted my efforts with documentation. Tell me where it explains how to put multiple form fields in a message. Or maybe a hint.