Page 1 of 1

PHPMailer - first PHP attempt - no work, no errors.

Posted: Mon Nov 20, 2006 6:54 pm
by ivj
I just finally got PHP to read my php.ini (from this thread: viewtopic.php?p=331711#331711), so now I'm trying to launch a very simple example.

I downloaded the PHPMailer libarary, place phpmailer.php in my /var/lib/php, and I'm trying to execute the following code:

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Test Mail...
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
//$mail->IsSMTP();
$mail->From = "admin@ablogic.net";
$mail->Host = "localhost";
$mail->AddAddress("ivj@comcast.net");
$mail->Subject = "Test SUbject";
$mail->Body = "Test Body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>
Second test...

</body>
</html>
It gets only executed as far as the "Test Mail..." HTML string, the rest doesn't get proccessed. No errors or anything. I check out my log file (/usr/local/apache2/logs/php.err) - but it doesn't even exist (and I do have it specified, here's my phpinfo: http://thailandhaven.com/test.php). There are no errors in the apache log either.

So what kind of BS is this?

Here's the output of the code btw:

http://thailandhaven.com/phpMailerTest.php

Posted: Mon Nov 20, 2006 7:00 pm
by RobertGonzalez
I know you have had enough php.ini for any person in a day, but you may want to turn display_error to On so you can see if there are any errors being thrown. This is only suggested for development environments as it can lead to potential security issues.

Posted: Mon Nov 20, 2006 7:03 pm
by ivj
Ok, turned it to On, restarted apache, still no php.err...

Posted: Mon Nov 20, 2006 7:14 pm
by feyd
Your include path is stated as ".:/usr/local/lib/php" .. is this particular broken file located in "/var/lib/php"?

Posted: Mon Nov 20, 2006 7:46 pm
by ivj
What file? http://thailandhaven.com/phpMailerTest.php ?

That one is where my apache serves them.

Posted: Mon Nov 20, 2006 7:49 pm
by ivj
The phpmailer class is located in /usr/local/lib/php, sorry about the /var/lib/php, i just thought that's what the folder was off the top of my head.

Posted: Mon Nov 20, 2006 8:06 pm
by volka
please try

Code: Select all

<html>
	<head>
		<title>Untitled Document</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	</head>
<body>
	<div>Test Mail...</div>
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

echo "<div>require</div>\n"; flush();
require 'class.phpmailer.php';

echo "<div>new PHPMailer</div>\n"; flush();
$mail = new PHPMailer();

echo "<div>properties</div>\n"; flush();
//$mail->IsSMTP();
$mail->From = "admin@ablogic.net";
$mail->Host = "localhost";
$mail->AddAddress("ivj@comcast.net");
$mail->Subject = "Test SUbject";
$mail->Body = "Test Body";

echo "<div>Send()</div>\n"; flush();
if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "<div>Message has been sent</div>"; flush();
?>
		Second test...
	</body>
</html>

Posted: Mon Nov 20, 2006 8:12 pm
by ivj

Posted: Mon Nov 20, 2006 8:13 pm
by ivj
Oh, and as before, no php.err in the specified folder ;(((

Posted: Mon Nov 20, 2006 8:39 pm
by volka
Let's take a closer look at the mail method phpmail is using.

Code: Select all

$mail->Body = "Test Body";

echo '<div>Mailer: ', $this->Mailer, "</div>\n";

echo "<div>Send()</div>\n"; flush();
if(!$mail->Send())

Posted: Mon Nov 20, 2006 8:41 pm
by ivj
Um, $this? Here's the output:

Test Mail...
require
new PHPMailer
properties
Mailer:
Fatal error: Using $this when not in object context in /usr/local/tomcat5/webapps/two.ablogic.net/ROOT/phpMailerTest.php on line 26

Posted: Mon Nov 20, 2006 8:41 pm
by volka
sorry, typo.
$mail->Mailer

Posted: Mon Nov 20, 2006 8:43 pm
by DaveTheAve
Not that you really want to hear this but I figure someone must say it, (I'm surprised no one did already)
I advise you switch over to SwiftMailer, it's a lot faster to use. Some comparisons can be found here: http://www.swiftmailer.org/phpmailer/; however, don't believe everything on the internet, run some of your own tests and see which is better for you.

Posted: Mon Nov 20, 2006 9:09 pm
by ivj
Wow!

Swift thing worked like a charm!

Thanks!

Posted: Mon Nov 20, 2006 9:19 pm
by DaveTheAve
No problem at all.