• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

Wonder if there is an Expert with understanding and experience with the PHPmailer script?

I have used the PHPmailer script for about 2 years.  Ran fine.  Then suddenly, in conjunction with an ISP server migration, the script stopped working.

The form processes user entered data to MySQL, and PHPmailer responds by sending an email to a list of addresses pulled from MySQL.

The error message is so cryptic, or general, that it's of no use.

If you have experience with PHPmailer and can help, I'd appreciate hearing from you.  I'll provide more details.
0
cgustaf
Asked:
cgustaf
  • 30
  • 17
  • 2
1 Solution
 
hieloCommented:
>>The error message is so cryptic,
Is it more cryptic than your description of the actual error message?
:)

>> an ISP server migration
are you using an SMTP server that requires authentication perhaps?
0
 
cgustafAuthor Commented:
!  The actual error message is:

"There has been a mail error<br>";

Which give no clues at all -- at least not for me.

Yes, I'm using SMTP, but the problem is not there because the form delivers the data to MySQL.  What is not working, however is the sending of the emails to addresses pulled from MySQL.

Do you want to see class.phpmailer.php and the mailing page itself where the error message is?
0
 
hieloCommented:
>>"There has been a mail error<br>";
That sounds like an error message generated by your php page not the phpmailer class.  From experience,
there are some webhosts that require you to authenticate to their smtp servers to send emails. If you were not doing this before, it's possible that now the new smtp server requires it. If so  you will need to provide the appropriate credentials.

To clarify, look at the following example:
http://phpmailer.worxware.com/index.php?pg=examplebsmtp

Notice lines 15-18.
There you are specifying the smtp host,port,the username and passwords. Find out from your current host if you need to authenticate and is so you will need the same info I just outlined.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
hieloCommented:
BTW: If in fact you are using SMTP - meaning if your script has:
$mail->IsSMTP();

then add this as well:
$mail->SMTPDebug  = 1;

to help you figure out the problem.

0
 
hieloCommented:
>>Do you want to see class.phpmailer.php and the mailing page itself where the error message is?
That certainly helps. Attach it.
0
 
cgustafAuthor Commented:
Thanks -- I'm looking at your suggestions and checkinig the script.  In the meantime, I attach the two files.
mail-list-3.php
0
 
cgustafAuthor Commented:
Here is the phpmailer file
class.phpmailer.php
0
 
cgustafAuthor Commented:
The authentication is implemented -- as I said, the same as in the Gammadyne mailer.  Also, there has been no change to this.  The mailing programs I use on this server have always operated as authenticated, and there is no change in credentials.

You see this in in class.phpmailer.php.

I tested the Debug function, but did not get a read-out anywhere that I could see.  Where should it be?
0
 
hieloCommented:
>>    if(!$mail->Send())
>>        echo "There has been a mail error<br>";
Exactly like I suspected. This will not help you.

In your mail-list-3.php file, after:
$mail->Mailer   = "smtp";

put:
$mail->SMTPDebug=true;

and see if you get any additional errors
0
 
cgustafAuthor Commented:
I get this:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
0
 
cgustafAuthor Commented:
Not sure what that means, but I do not have a local MySQL server, only the remote.
0
 
hieloCommented:
also change:
echo "There has been a mail error<br>" ;

to:
echo "There has been a mail error<br>" . $mail->ErrorInfo;

what do you get?
0
 
cgustafAuthor Commented:
Wait -- That was not a good test.  I'm doing it over.
0
 
cgustafAuthor Commented:
I only get this error:  Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
0
 
cgustafAuthor Commented:
The mail+_list_3.php attached as it looks now.
mail-list-3.php
0
 
cgustafAuthor Commented:
Type in file name -- is mail_list_3.php -- sorry
0
 
hieloCommented:
On the same folder where you have class.phpmailer.php, do you have a file named class.smtp.php? It seems that class.phpmailer.php requires that file.

>> Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
verify your server name => sqlc40b.carrierzone.come (should it end in 'e'?  that looks suspiciously wrong)
0
 
cgustafAuthor Commented:
OK  Now we are doing better.  I discovered a typo in the script and correcte this.  This resulted in the following errors reported:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) There has been a mail error
SMTP Error: Could not connect to SMTP host.
0
 
cgustafAuthor Commented:
Yes, You found the same error as I found.  .com not .come  I corrected that and then the above errors were reported.
0
 
cgustafAuthor Commented:
Yes, there is a class.smtp.php file as part of the packet.  It is in the same directory as class.phpmailer.php .
0
 
cgustafAuthor Commented:
It looks like the error is caused somewhere around lines 27-30 in mail_list_3.php :

$mail->From     = "gustafsson@ibtpartners.org";
$mail->FromName = "Curt and Elvy Gustafsson";
$mail->Host     = "smtp.ibtpartners.org";
$mail->Mailer   = "smtp";
$mail->SMTPDebug = true;

I do not understand the interaction between class.phpmailer.php and mail_list_3.php, but the authentication is not complet in latter but it is complete in the prior.-- except that in class.phpmailer.php we have:

   var $Hostname          = "ibtpartners.org";

and

    var $Host        = "smtp.ibtpartners.org";

Don't understand  var $Hostname          = "ibtpartners.org";
0
 
hieloCommented:
>>SMTP -> ERROR: Failed to connect to server: Connection timed out (110) There has been a mail error
SMTP Error: Could not connect to SMTP host.
There you go, that helps. Now you need to find out from your host why this is happening?
Do you have the right port number?
Do you have the right smtp server?
What about username/password on smtp server?
Is the smtp server not accepting connections/request from your new hosting machine?

As an experiment, do you have some other smtp you can use? For instance, if you have a gmail account, provide  the gmail credentials and see if you can send emails from it. BEFORE you contact your service provider, you want to rule out script problems. That way you can honestly say "It works fine if I use an smtp server other than yours. What gives?".
0
 
cgustafAuthor Commented:
OK thanks for this reasoning.  Here I review the autehtication and credentials:

Host:  smtp.ibtpartners.org
Port: 587
User: gustafsson@ibtpartners.org
Pw: ...password...

These are correct in class.phpmailer.php

Also, I use the same authentication in Gammadyne Mailer (it also goes directly on the SMTP), and I use the same SMTP server for outgoing Outlook mail with the same authentication and credentials.  Both of theses work normally now.

So, it seems to me that the failure is not caused by authentication or credentials errors.

If that is true, what else could be wrong?


0
 
hieloCommented:
>>var $Host        = "smtp.ibtpartners.org";
That is your actual smtp host server. The error above:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110) There has been a mail error
SMTP Error: Could not connect to SMTP host.

refers to:
var $Host        = "smtp.ibtpartners.org";

Basically your script is trying to connect to smtp.ibtpartners.org to send an email, but that server is not "responding". Is it online?
0
 
hieloCommented:
>>what else could be wrong?
It's possible that the smtp server is not allowed to relay email from your new machine. That's why I said earlier "Is the smtp server not accepting connections/request from your new hosting machine?"

>>  Then suddenly, in conjunction with an ISP server migration
What about firewalls? If you have one in place, just for purposes of debugging, try disabling it and try.
0
 
cgustafAuthor Commented:
I have now done a test using Gammadyne mailer sending mail through the same SMTP server from the same local machine I'm using with PHPmailer.  No errors were reported in Gammadyne Mailer, and the mail went through.  I received it.

Could there be some interaction between class.phpmailer.php and mail_list_3.php that is not functioning correctly.

By the way, I have to stop working on this for today, and will picik it up again tomorrow.  If you are not available, we will wait until Monday.
0
 
hieloCommented:
>>Could there be some interaction between class.phpmailer.php and mail_list_3.php that is not functioning correctly.
Not from what I can see? The issue here is that it is not connecting with the  server. IF the problem was an interaction between the class definition and your actual form/page, then it would at least connect.
0
 
cgustafAuthor Commented:
Using the worxware sample (you sent the link) as a guide, I made up an smtp_test file just to see if I could isolate the connection problems.  The file runs, it shows no errors, but it does not deliver the email to the hardcoded address in the file.

Here is the code for your review:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMTP TEST</title>
</head>
<body>
<?php
require("class.phpmailer.php");
include("class.smtp.php");
$mail->IsSMTP();                           // telling the class to use SMTP
$mail->Host       = "smtp.ibtpartners.org"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.ibtpartners.org"; // sets the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the GMAIL server
$mail->Username   = "gustafsson@ibtpartners.org"; // SMTP account username
$mail->Password   = "...password...";        // SMTP account password
$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$address = "gustafsson@ibtpartners.org";
?>
</body>
</html>
0
 
hieloCommented:
Since you migrated to a new host, do you know what version of php you are currently using? The version of the mailer you have is for php4. I'm not sure it that would be an issue. I've always used version 5.*

Other than version incompatibilities, the only other thing I can think of is that it might be a firewall issue.
0
 
Ray PaseurCommented:
@cgustaf: hielo asked if I would look at this Q.  I have used PHPMailer before but not extensively and my memory of its quirks is somewhat rusty.  Also, I have never used the PHP4 version.  You might want to check phpinfo(); to be sure your PHP and PHPMailer are matched versions.

Regarding this:  "The file runs, it shows no errors, but it does not deliver the email to the hardcoded address in the file." - is there any chance a spam filter could be involved?  If you want to change the address to mine, please use Ray.Paseur at GMail (you know the right address) and send me a test message.  Post here when you do that.  If you want to simplify the test case and just send plain text "hello world" that is fine.

Standing by in case I can help, ~Ray
0
 
cgustafAuthor Commented:
Hi Ray -- I had to be away for a while and did not see your message until now.  I will set up so I can send you a message, and will let you know here when it is done.  /curt
0
 
cgustafAuthor Commented:
> You might want to check phpinfo(); to be sure your PHP and PHPMailer are matched versions.

Maybe this is the problem.  I checked, and the PHP version provided by the ISP is 5.2.9  .

This is an upgrade that must have taken place at the time they migrated to a new server setup.  Unfortunately, no notice of this change was published, to my knowledge.  Going into the migration we were at 4.x .

So, I should check to see if PHPmailer has been upgraded work with PHP 5.
0
 
cgustafAuthor Commented:
There is a PHPmailer version "for PHP 5/6"  I will try to install that and we'll see what happens.  It will take me a while.
0
 
cgustafAuthor Commented:
Hi Ray and hileo -- I have installed PHPmailer 5.1 (which requires PHP 5 or better).  But, the results are the same -- no connection.

I'm going to try the gmail route next, but not today.
0
 
Ray PaseurCommented:
OK, please post back here when you have sent me a message at my GMail address and I will try to find it.  Best of luck with it, ~Ray
0
 
cgustafAuthor Commented:
I have now tested Gmail by sending to my own  address.  There are no error message, and no mail is delivered.  I attach gmail_test.php and class.phpmailer.php and class.smtp.php for your perusal.

Seems only one file can be attached to a message sent here, so there will be a total of 3 messages.
gmail-test.php
0
 
cgustafAuthor Commented:
class.phpmailer.php
class.phpmailer.php
0
 
cgustafAuthor Commented:
class.smtp.php
class.smtp.php
0
 
hieloCommented:
Did you try disabling the firewall as previously suggested?
Also, provide your email address on the script below and try:
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
if(  mail($to, $subject, $message, $headers) )
{
 echo "OK";
}
else
{
 echo "no luck";
}
?>

Open in new window

0
 
cgustafAuthor Commented:
I tested the script by sending TO three addresses FROM gustafsson@ibtpartners.org

TO: gustafsson@ibtpartners.org, gustafsson@ibtnet.org, curt.gustaf@gmail.com

All three addresses worked -- I received the emails.

Here is the edited script:

<?php
$to      = 'gustafsson@ibtpartners.org';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: gustafsson@ibtpartners.org' . "\r\n" .
    'Reply-To: gustafsson@ibtnet.org' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
if(  mail($to, $subject, $message, $headers) )
{
 echo "OK";
}
else
{
 echo "no luck";
}
?>
0
 
hieloCommented:
OK, then if you want to continue using the phpmailer class, you can use:
$mail->IsMail();  

INSTEAD OF
$mail->IsSMTP();  

WIth that change in place, phpmailer will use the mail() function instead of the SMTP.  As for your SMTP problems, my guess is that it is related to firewall or permissions.

For example, if you php script is running on machine A and your smtp is running on machine B, and both machines exist on different networks, then for security purposes it is possible that machine B is configured to NOT allow email relaying from machines outside it's own network. So make sure that machine B explicitly allows machine A to relay emails.
0
 
cgustafAuthor Commented:
Thanks -- Question:  On a couple of occasions (above) I have stated that I use another program for "mass" mailing (in my case only about 800 address total).  That program is called Gammadyne Mailer and is built specifically for mass emailing.  It is a professional program and used by a number of large companies.  

In Gammadyne Mailer, I have set up the SMTP send function identically to what I have been testing in the PHPmailer.(Host, User, PW), and this works all the time.

I am using only one machine for all my work, although I'm accessing the internet over a LAN connection.

Further, my SMTP email settings in Outlook are identical to the seetings in PHPMailer and Gammadyne Malier.  Works every time.

Thus, I don't understand why these settings don't work in PHPmailer any longer -- as I said initially, they have worked previoulsy, for a couple of years.

QUESTION:  Is it possible to change the above test script so it will send via SMTP rather than mail()?  Perhaps such a test would provide some additional clues.
0
 
hieloCommented:
mail() does not support smtp authentication. Hence the reason why phpmailer has the explicit options:
IsSMTP() and IsMail().

On another note, you can also try opening port 25 (non-secure port) on your smtp server and attempt to send via that port from phpmailer.
0
 
cgustafAuthor Commented:
Using mail() rather than  SMTP, I have now restored the service so that emails are sent to addresses in the MySQL database table when a user adds a record to another table in the same database.

Thanks for your help so far.

I would like to better understand the drawbacks of using mail() over SMTP.  Mail provides no authentication, but what is the actual impact of loss of authentication?  What are the security issues and dangers?

If you can provide some guidance on this, I'll be grateful.
0
 
hieloCommented:
In your case, it wouldn't make a difference. The reason for this is that you are sending emails via a php script. If you use SMTP, it is the SCRIPT that is authenticating and then sending the email. If you use mail(), there is no authentication and the emails are still sent. From the point of view of your users, they don't know nor care what you are doing in the back end. All they know is that somehow you are sending emails.

As for security concerns, well if your SMTP is declining connections, then you are definitely secure :)
As for your mail(), you will need some script to send emails out. You cannot "authenticate" directly to your mail() function. You would need a php script in place that makes use of your mail() (which is what you are currently doing).

Regards,
Hielo
0
 
cgustafAuthor Commented:
So, are you saying that mail() is not as secure as authenticated SMTP?  If so, what is it that authenticated SMTP protects the user from that mail() does not?

It seems to me that with a PHP script, even authenticated SMTP is really not that water tight since the credentials are clearly visible in the script and could conceivably be picked up by a snooper without much effort.  With this, the differences between using mail() and authenticated SMTP, as far as security is concerned, are really not that great.

Am I understanding this somewhat correctly?
0
 
hieloCommented:
mail() is a php function. If you do not have php running, mail() will not work. It needs to run within the context of a php script. The SMTP is independent of php. That's why you have various email clients that connect and authenticate to your SMTP server. The point of that authentication is that you do not want the whole world to use your smtp server to be sending email out.

>>It seems to me that with a PHP script, even authenticated SMTP is really not that water tight.
That's exactly what I was referring to when I said "In your case, it wouldn't make a difference...".

Your TRUE security relies on the security of your WEB server. IF your server is hacked and somehow they managed to steal your php source code then the hacker would have your SMTP credetials and would legitimately authenticate to your smtp server for purposes of spamming.

>>are clearly visible in the script and could conceivably be picked up by a snooper
If you create a php file:
<?php
$user="john";
phpinfo();
?>

and then load it via the browser, the WEB SERVER will NOT send the php source code. It will send the RESULT of executing that php script. On the example above, after you visit that page, if you look at the browser's source code you will NOT see the php code, so you will NEVER know that there is such thing as $user="john". The only thing you will see will be the result of the phpinfo() built-in function.

So this "since the credentials are clearly visible in the script " is not a simple as you make it sound. YOU (cgustaf) have access to the php script because it is your server and have permissions to download/read/modify the ACTUAL php source code, but the public does not. Again, your webserver does NOT send the PHP code to the browser.

0
 
cgustafAuthor Commented:
Thanks for this clear explanation.  I appreciate it.

It seems perfectly OK, then, to use mail() in my case.  The fact that the PHP script is protected by whatever security the server provides, and perhaps also by encrypted transport (https:// -- which I use when user data is transported), it appears that mail() is no less secure a method than authenticated SMTP.  And, from what I can see it is no slower.

With this, thanks for your help wading through this to the point of finding a solution.  Both you and Ray have displayed a sincere desire to help.  This, I greatly appreciate.  I'm concluding this matter, and am awarding you the points!

Curt L. Gustafsson
0
 
cgustafAuthor Commented:
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 30
  • 17
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now