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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

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

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post by ivj »

Ok, turned it to On, restarted apache, still no php.err...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your include path is stated as ".:/usr/local/lib/php" .. is this particular broken file located in "/var/lib/php"?
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post by ivj »

What file? http://thailandhaven.com/phpMailerTest.php ?

That one is where my apache serves them.
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post by ivj »

ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post by ivj »

Oh, and as before, no php.err in the specified folder ;(((
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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())
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

sorry, typo.
$mail->Mailer
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post 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.
ivj
Forum Commoner
Posts: 31
Joined: Sat Mar 05, 2005 3:07 am

Post by ivj »

Wow!

Swift thing worked like a charm!

Thanks!
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

No problem at all.
Post Reply