Page 1 of 1

Black Page... handle_form.php

Posted: Mon Dec 24, 2007 3:33 am
by aminamin
Hey Guys,

I've just installed SwifMailer as I need to create a form which allows uers to upload an image of themselves and then emails it to me as an attachment along with the rest of the message.

I'm testing the form.php and Handle_form.php files the form validation works ok... but when all fields are completed i get a blank page that stops with the url bing htt://....../handle_form.php.

this is my handle_form.php code:

Code: Select all

<?php

require_once "/includes/config.inc.php";
 
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
    || empty($_POST["comment_title"]) || empty($_POST["comment_body"]))
{
    //redirect back to form
    header("Location: ./form.php?error=not_enough_info"); //This should really be an absolute URL if you know it
    exit();
}
 
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];
 
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
    header("Location: ./form.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: ./form.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 "swift/Swift.php";
require_once "swift/Swift/Connection/SMTP.php";
 
//Enable disk caching if we can
if (is_writable("/tmp"))
{
    Swift_CacheFactory::setClassName("Swift_Cache_Disk");
    Swift_Cache_Disk::setSavePath("/tmp");
}
 
//Create a Swift instance

$smtp =& new Swift_Connection_SMTP(
    "stmp.www.com", 25);
      $smtp->setUsername("1123");
      $smtp->setpassword("1234");
 
$swift =& new Swift($smtp); 
 
//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("New comment: " . $title);
$message->attach(new Swift_Message_Part($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, "emai@email.com", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
 
if ($sent)
{
    header("Location: ./success.php");
    exit();
}
else
{
    header("Location: ./form.php?error=sending_failed");
    exit();
}
?>
the only changes made are to the smtp settings, ive also added a confic.inc.php file which i hoped would help with any errors... but none are received.

rather than using stmp.website.com can i use mail.webiste.com?...

any help to resolves this would be great!

Posted: Mon Dec 24, 2007 3:55 am
by s.dot
If you're sure PHP errors are being sent, enable the swift logger right after you instantiate Swift.

Code: Select all

//get the log container
$log = Swift_LogContainer::getLog();

//log everything
$log->setLogLevel(4);

//the rest of your code here

//get the log now
$log = Swift_LogContainer::getLog();
echo $log->dump(true);
If you're still getting a blank page, it's likely a parse error in your code.

Posted: Mon Dec 24, 2007 5:04 am
by aminamin
still not receiving any errors...

and still receiving a white blank page.

im abit lost at what else I can try.. im pretty sure there are no errors within the coding itself

Posted: Mon Dec 24, 2007 5:39 am
by s.dot
In your script (if you can't make a .htaccess file or are not running on apache)

Code: Select all

ini_set('display_errors', 'On');
error_reporting(E_ALL);
.htaccess file, if you can

Code: Select all

php_flag display_errors On
A blank page is generally a very good indication that a fatal error has occured (such as a parse error.. can't find required files.. etc). Have you tried echoing text in the script?

Code: Select all

echo 'I should printttttttttttt';
exit;