Black Page... handle_form.php

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
aminamin
Forum Newbie
Posts: 2
Joined: Mon Dec 24, 2007 3:09 am

Black Page... handle_form.php

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
aminamin
Forum Newbie
Posts: 2
Joined: Mon Dec 24, 2007 3:09 am

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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;
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply