multiple errors after using tutorial
Posted: Mon Sep 24, 2007 11:09 am
I used the tutorial that I found in the swiftmailer.org wiki docs and made what I thought were the necessary changes and received the following errors:
and the form handler is:
my it guy is checking to make sure the mail server is working properly but since there was the undefined constant I thought I'd check here as well
thanks!
the form code is:Notice: Use of undefined constant self::LOG_NOTHING - assumed 'self::LOG_NOTHING' in /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/mailer/lib/Swift/LogContainer.php on line 43
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'The SMTP connection failed to start [67.78.206.201:25]: fsockopen returned Error Number 110 and Error String 'Connection timed out'' in /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/mailer/lib/Swift/Connection/SMTP.php:309 Stack trace: #0 /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/mailer/lib/Swift/Connection/SMTP.php(309): Swift_Connection_SMTP::start() #1 /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/mailer/lib/Swift.php(216): Swift_Connection_SMTP->start() #2 /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/mailer/lib/Swift.php(101): Swift->connect() #3 /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/handle_form.php(53): Swift->__construct(Object(Swift_Connection_SMTP)) #4 {main} thrown in /var/www/vhosts/shoppingcenter-advisor.com/httpdocs/test/users/mailer/lib/Swift/Connection/SMTP.php on line 309
Code: Select all
<?
error_reporting(E_ALL);
session_start();
require_once("functionlist.php");
//Check to see if admin session is set
if ($_SESSION['users'] !="admin")
{
session_write_close();
page_redirect('index.php');
exit();
}
$login=$_SESSION['userid'];
include_once("userroutines.php");
doconnect();
$query="SELECT username,first,last from users where username='" . $_SESSION['userid'] . "'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$date=date('m/j/y');
$page_title=("Shopping Center Advisor - Add User - " . $date . " - User: " . $row['first'] . " " . $row['last']);
mysql_free_result($result);
?>
<!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>
<title><?php echo $page_title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/shadow.css" media="screen" />
<script type="text/javascript" src="includes/shadow.js"></script>
<script type="text/javascript" src="../includes/opennew.js"></script>
<link rel="shortcut icon" href="../favicon.ico" />
</head>
<body>
<div id="main-wrap" class="shadow">
<div id="col-wrap">
<div id="left-col">
<div id="left-nav-container">
<p class="toplink">Functions:</p>
<ul>
<li class="toplink"><a href="<? echo $_SERVER['PHP_SELF']; ?>?signout=1">Sign Out</a>
<li><a href="updateindex.php">Update "Index" content</a></li>
<li><a href="user_add.php">Add User</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="user">
<h1><?php echo $page_title; ?></h1>
</div>
<p>Complete the form below to add a new user</p>
<?php
//Display an error if something went wrong
if (!empty($_GET["error"]))
{
switch ($_GET["error"])
{
case "not_enough_info": ?>
<strong style="color: red;">You need to complete all fields marked *<strong><?php
break;
case "invalid_email": ?>
<strong style="color: red;">Please provide a valid email address</strong><?php
break;
case "upload_failed": ?>
<strong style="color: red;">The file you uploaded failed to attach, this could be a temporary problem.
Please try later.</strong><?php
break;
case "sending_failed": ?>
<strong style="color: red;">Temporary problem, please try later.</strong><?php
break;
}
}
?>
<form action="handle_form.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td class="label">First Name *</td>
<td><input type="text" name="sender_name_1" value="" /></td>
</tr>
<tr>
<tr>
<td class="label">Last Name *</td>
<td><input type="text" name="sender_name_2" value="" /></td>
</tr>
<tr>
<td class="label">E-mail address *</td>
<td><input type="text" name="sender_email" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<div class="clearfix"></div>
<div id="footer"><?php include("../includes/footermenu.inc") ?></div>
</div>
</body>
</html>Code: Select all
<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name_1"]) || empty($_POST["sender_name_2"]) || empty($_POST["sender_email"]))
{
//redirect back to form
header("Location: ./user_add.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_1"];
$email = $_POST["sender_email"];
//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: ./user_add.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: ./user_add.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 "mailer/lib/Swift.php";
require_once "mailer/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");
}
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("67.78.206.201"));
//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, "your@address.tld", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: ./success.php");
exit();
}
else
{
header("Location: ./user_add.php?error=sending_failed");
exit();
}
?>thanks!