I'm using the example and trying to send mail via my hosted gmail account. Here's what I have so far in the handle_form.php file. The form.php file is exactly like the tutorial on your site.
I tried turning on the logging for more information, but got nowhere. I am using php4 and have the correct swift version.
Code: Select all
<?php
$log =& Swift_LogContainer::getLog();
$log->setLogLevel(4);
//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 "lib/Swift.php";
require_once "lib/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");
}
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to Gmail (PHP4)
$swift =& new Swift(new Swift_Connection_SMTP("smtp.gmail.com", SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS));
$smtp->setUsername('support@mydomain.com');
$smtp->setPassword('password');
$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, "support@mydomain.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();
$log =& Swift_LogContainer::getLog();
echo $log->dump(true);
?>Line 100 is the last line of my handle_form.php file.Parse error: syntax error, unexpected $end in /home/username/public_html/contactus/handle_form.php on line 100
Everything else is done exactly as the documentation on your site shows. Please help if you do not mind. I would GREATLY appreciate it.
Thank you,
Nick