Page 1 of 1

multiple errors after using tutorial

Posted: Mon Sep 24, 2007 11:09 am
by bernadette
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:
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
the form code is:

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>
and the form handler is:

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();
}

?>
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!

Posted: Mon Sep 24, 2007 1:10 pm
by chuckl
What PHP version is the server/machine running, and are you using the matching Swift version?

I think you should be more concerned about the fsock timeout, which means that you are not connecting to anything. Does the mail server not need some form of authentication?

Posted: Mon Sep 24, 2007 1:20 pm
by bernadette
I've been told that the php version is 5.2.2 and that authentication is not required

Posted: Mon Sep 24, 2007 1:57 pm
by chuckl
I wouldn't worry too much about the undefined message at this stage, it's a side effect of the error or the E_ALL probably.

At this stage I'd suggest using telnetfrom a terminal window or something to connect to the mail server and see what it's responses are.

telnet 67.78.206.201 25

then try an EHLO command and see what login options if any it throws up, or whether it is listening on port 25

Posted: Mon Sep 24, 2007 3:25 pm
by bernadette
your telnet suggestion was quite helpful and it did point out a server hiccup

the other issue was I was using the wrong ip address (even though that was the one that was provided to me) and then ultimately I didn't need an ip at all...localhost worked just fine

Posted: Mon Sep 24, 2007 4:26 pm
by Chris Corbyn
Lines 39 - 45 in Swift_LogContainer are these:

Code: Select all

public static function getLog()
  {
    if (self::$log === null)
    {
      self::setLog(new Swift_Log_DefaultLog());
    }
    return self::$log;
  }
I'm not sure how you could get that error? Does your Swift/LogContainer.php file look different at all?

Posted: Wed Sep 26, 2007 9:20 am
by bernadette
sorry for the delay...

I haven't made any changes to the Swift_LogContainer - they are as I copied them from the files downloaded...

Posted: Wed Oct 17, 2007 9:19 am
by thrunx
bernadette wrote:sorry for the delay...

I haven't made any changes to the Swift_LogContainer - they are as I copied them from the files downloaded...
I have the exact same problem:

Code: Select all

Notice: Use of undefined constant self::LOG_NOTHING - assumed 'self::LOG_NOTHING' in /var/www/html/includes/swift-php5/Swift/LogContainer.php on line 43
I just downloaded the files a couple of days ago and I did not change anything. I run PHP 5, Swift version 3.3.2 and use the Native-way of sending.

Posted: Wed Oct 17, 2007 6:26 pm
by Chris Corbyn
Hmm... I'll get back to you in a few hours. I don't refer to that constant anywhere in that file :?

Posted: Wed Oct 17, 2007 8:47 pm
by RobertGonzalez
The LOG_NOTHING constant is defined in Swift_Log at line 37. It is set into the value of $logLevel at line 68 of Swift_Log. It is also checked in isEnabled.

Posted: Wed Oct 17, 2007 9:16 pm
by Chris Corbyn
Everah wrote:The LOG_NOTHING constant is defined in Swift_Log at line 37. It is set into the value of $logLevel at line 68 of Swift_Log. It is also checked in isEnabled.
But never anywhere in Swift_LogContainer :?

Code: Select all

<?php

/**
 * A registry for the logger object.
 * Please read the LICENSE file
 * @author Chris Corbyn <chris@w3style.co.uk>
 * @package Swift_Log
 * @license GNU Lesser General Public License
 */

require_once dirname(__FILE__) . "/ClassLoader.php";
Swift_ClassLoader::load("Swift_Log_DefaultLog");

/**
 * A registry holding the current instance of the log.
 * @package Swift_Log
 * @author Chris Corbyn <chris@w3style.co.uk>
 */
class Swift_LogContainer
{
  /**
   * The log instance.
   * @var Swift_Log
   */
  protected static $log = null;
 
  /**
   * Registers the logger.
   * @param Swift_Log The log
   */
  public static function setLog(Swift_Log $log)
  {
    self::$log = $log;
  }
  /**
   * Returns the current instance of the log, or lazy-loads the default one.
   * @return Swift_Log
   */
  public static function getLog()
  {
    if (self::$log === null)
    {
      self::setLog(new Swift_Log_DefaultLog());
    }
    return self::$log;
  }
}

Posted: Wed Oct 24, 2007 1:50 am
by thrunx
If you add this in the class, the error disappears. I'm only not sure what concequeses it has, but it doesn't matter for me. I'm not going to look at the log-file ;-)

Code: Select all

const LOG_NOTHING = 0;