Web Hosting Forum | Lunarpages

Author Topic: Frustrated with PHPMailer  (Read 5373 times)

Offline Bandi

  • Space Explorer
  • ***
  • Posts: 6
Frustrated with PHPMailer
« on: September 18, 2017, 09:40:43 PM »
For days I have been trying to make 'PHPMailer 5.2-stable' or -master work to replace FormMail which has problems lately. You will find that I know only what I find in examples and can follow instructions but do not know php programming. Sigh. Please help!

All programs (such as smtp.php from examples in 'PHPMailer 5.2-stable' ) always fail at creating a new PHPMailer instance, so that I can not proceed any further:

Code: [Select]
<?php
/**
 * This example shows making an SMTP connection with authentication.
 */
ini_set('display_errors',1);
error_reporting(E_ALL);
date_default_timezone_set('Etc/UTC');

require 
'../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;

I get error messages:
"Warning: require(../PHPMailerAutoload.php): failed to open stream: No such file or directory in
/home/***/public_html/sfkornyek/smtp.php on line 15
Fatal error: require(): Failed opening required '../PHPMailerAutoload.php' (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home/***/public_html/sfkornyek/smtp.php on line 15"

If I change to
require '../PHPMailer/PHPMailerAutoload.php';
or to
require '/home/***/public_html/sfkornyek/PHPMailer/PHPMailerAutoload.php';
the error messages are the same as above
Of course, all folders shown are there and php is enabled,

The "include_path" in the error message bothers me but I do not know where or how to include it.
PHPMailerAutoload.php does not look like it requires such modification but correct me please!

<removed account name -- Mod.>
« Last Edit: September 19, 2017, 05:26:22 AM by MrPhil »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6230
Re: Frustrated with PHPMailer
« Reply #1 on: September 19, 2017, 05:34:23 AM »
You shouldn't need to change (or even worry about) the include_path, so long as it contains the entry '.' (current directory). If you do need to set it, that would be done in a php.ini file (you might have to create it, and add an entry in .htaccess pointing to it).

The error message is telling you that wherever you're running smtp.php, it's looking for a file PHPMailerAutoload.php in that directory's parent directory (one level up). That would appear to be /home/***/public_html/ in your case. Is that where PHPMailerAutoload.php lives? If not, what is the path to it? If it's there, what are its permissions? If they're unreadable for some reason, it will be "not found" or "not readable".
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline Bandi

  • Space Explorer
  • ***
  • Posts: 6
Re: Frustrated with PHPMailer
« Reply #2 on: September 21, 2017, 10:04:11 AM »
Thank you for your help.
I did nothing to include_path for now.

smtp.php resides in
home/***/public_html/sfkornyek/

PHPMailerAutoload.php location was
home/***/public_html/sfkornyek/PHPMailer/PHPMailerAutoload.php';
and I moved it to
home/***/public_html/sfkornyek/
The warnings are the same as listed originally

I then moved PHPMailerAutoload.php to
home/***/public_html/
and got
Fatal error: Class 'PHPMailer' not found in /home/***/public_html/sfkornyek/smtp.php on line 18
line 18 is $mail = new PHPMailer;

I continue scratching my head. Path should indicate where to look for a dependent file unless somehow a default location is built into php <- am I far off?

<***-out account name -- Mod.>
« Last Edit: September 21, 2017, 03:09:39 PM by MrPhil »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6230
Re: Frustrated with PHPMailer
« Reply #3 on: September 21, 2017, 04:20:45 PM »
Uh, let's back up to the beginning. First of all, are smtp.php and PHPMailer two separate products, or are they installed together? You didn't misread /PHPMailer/Autoload.php as /PHPMailerAutoload.php, right? PHPMailer is the basic product, and smtp.php is an example program supplied by PHPMailer that uses PHPMailer? Where was PHPMailer originally installed... in /sfkornyek? Did the instructions for smtp.php say anything about where to install smtp.php, such as in PHPMailer? Did you move anything in the process?

If smtp.php is supposed to make use of PHPMailer, it would have to know where PHPMailer is. If, say, PHPMailer is in /sfkornyek/PHPMailer/, and the smtp.php example is installed in /sfkornyek/, I would think that it would look for PHPMailerAutoload.php in
Code: [Select]
require 'PHPMailer/PHPMailerAutoload.php';not ../.

If smtp.php was installed in a new directory under PHPMailer (say, /sfkornyek/PHPMailer/examples/), then
Code: [Select]
require '../PHPMailerAutoload.php';would be correct. Re-read the smtp.php example instructions and see if you missed anything about where it's being installed.
« Last Edit: September 21, 2017, 04:24:50 PM by MrPhil »
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline Bandi

  • Space Explorer
  • ***
  • Posts: 6
Re: Frustrated with PHPMailer
« Reply #4 on: September 24, 2017, 09:57:45 PM »
Sorry for the lack of more details. Reading this section of Lunarforums, I got the feeling that all know PHPMailer inside out and tried to minimize verbiage :)
The following may clear this up.

The PHPMailer folder resides in CPanel's public_html/sfkornyek

-------------
The content of PHPMailer folder is
Folders:
github
examples
extras
language
Files:
class.phpmailer.php
class.phpmaileroauth.php   
class.phpmaileroauthgoogle.php
class.pop3.php
class.smtp.php
composer.json
composer.lock
get_oauth_token.php
LICENSE
PHPMailerAutoload.php
VERSION
CPanel Permissions, folders 0755, files 0644
-------------     

All of the folder content came from PHPMailer-5.2-stable.zip originating in https://github.com/PHPMailer/PHPMailer/releases and straightforward copied to folder PHPMailer.

Smtp.php is a program (taken from examples folder for the test and is running in public_html/sfkornyek). PHPMailer is a folder.

Smtp.php calls PHPMailerAutoload.php in PHPMailer folder, using
 require '/home/***/public_html/sfkornyek/PHPMailer/PHPMailerAutoload.php';

Then (I am guessing) PHPMailerAutoload.php calls class.phpmailer.php in this same folder
(Also see NOTE at the bottom)
-----------------------------------------
This is the complete PHPMailerAutoload.php code
Code: [Select]
<?php
/**
 * PHPMailer SPL autoloader.
 * PHP Version 5
 * @package PHPMailer
 * @link [url=https://github.com/PHPMailer/PHPMailer/]https://github.com/PHPMailer/PHPMailer/[/url] The PHPMailer GitHub project
 * @author Marcus Bointon (Synchro/coolbru) <[email]phpmailer@synchromedia.co.uk[/email]>
 * @author Jim Jagielski (jimjag) <[email]jimjag@gmail.com[/email]>
 * @author Andy Prevost (codeworxtech) <[email]codeworxtech@users.sourceforge.net[/email]>
 * @author Brent R. Matzelle (original founder)
 * @copyright 2012 - 2014 Marcus Bointon
 * @copyright 2010 - 2012 Jim Jagielski
 * @copyright 2004 - 2009 Andy Prevost
 * @license [url=http://www.gnu.org/copyleft/lesser.html]http://www.gnu.org/copyleft/lesser.html[/url] GNU Lesser General Public License
 * @note This program is distributed in the hope that it will be useful - WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * PHPMailer SPL autoloader.
 * @param string $classname The name of the class to load
 */
function PHPMailerAutoload($classname)
{
    
//Can't use __DIR__ as it's only in PHP 5.3+
    
$filename dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
    if (
is_readable($filename)) {
        require 
$filename;
    }
}

if (
version_compare(PHP_VERSION'5.1.2''>=')) {
    
//SPL autoloading was introduced in PHP 5.1.2
    
if (version_compare(PHP_VERSION'5.3.0''>=')) {
        
spl_autoload_register('PHPMailerAutoload'truetrue);
    } else {
        
spl_autoload_register('PHPMailerAutoload');
    }
} else {
    
/**
     * Fall back to traditional autoload for old PHP versions
     * @param string $classname The name of the class to load
     */
    
function __autoload($classname)
    {
        
PHPMailerAutoload($classname);
    }
}

PHPMailer folder and content was and is installed as shown above in sfkornyek.
Smtp.php had no installation instructions. I also tested it by moving it to PHPMailer folder, but it seems to indicate installation in one directory up from PHPMailerAutoload.php location,, so I moved it:

---------------------------------------

This is the pertinent part of the original smtp.php code
Code: [Select]
<?php
/**
 * This example shows making an SMTP connection with authentication.
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require 
'../PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
...
NOTE

My domain is szabadsagharcos.org. A Hungarian community website.

Index.html is my main program that needs webmail. Once the error messages are solved, it will activate an html form that passes the mail to PHPMailer package.
 
I will have 2 more standalone webmails. All 3 will replace FormMails that LunarPages still recommends but which have real problems with the server after a decade of no problems. LunarPages support recently recommended php based mailprogram.

Moving smtp.php to PHPMailer folder
then calling smtp.php from index.html in sfkornyek folder with
http://sfkornyek.szabadsagharcos.org/PHPMailer/smtp.php
results in 2 error messages:
Code: [Select]
The requested URL /PHPMailer/smtp.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

calling smtp.php from sfkornyek folder with
../PHPMailer/smtp.php
gets the same error messages

<remove account name -- Mod.>
« Last Edit: September 25, 2017, 04:48:35 AM by MrPhil »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6230
Re: Frustrated with PHPMailer
« Reply #5 on: September 25, 2017, 04:43:28 AM »
I take it you've properly set up and tested your subdomain http://sfkornyek.szabadsagharcos.org/HelloWorld.html, where HelloWorld.html is in /home/***/public_html/sfkornyek/. You used the cPanel or LPCP function to set up a subdirectory "sfkornyek", and didn't simply create the subdirectory? Assuming the subdomain is working...

public_html/sfkornyek/
   PHPMailer/
       PHPMailerAutoload.php   et al.

If smtp.php is installed in PHPMailer/, you would use require 'PHPMailerAutoload.php'; in the smtp.php file, and call it with http://sfkornyek.szabadsagharcos.org/PHPMailer/smtp.php

If smtp.php is installed in a directory below PHPMailer/, such as PHPMailer/mail/smtp.php, you would use require '../PHPMailerAutoload.php'; and call it with http://sfkornyek.szabadsagharcos.org/PHPMailer/mail/smtp.php

If smtp.php is installed at the same level as PHPMailer/ (public_html/sfkornyek/smtp.php) you would use require 'PHPMailer/PHPMailerAutoload.php'; and call it with http://sfkornyek.szabadsagharcos.org/smtp.php

Let's take care of that, and I think it will fix the class issue.

The "404 Not Found" error could be cleared up by creating your own "error documents" such as /404.shtml. If you're on cPanel, I think they still have a function to create a basic set, or you can write them yourself, or see http://www.catskilltech.com/FreeSW/faqs/index.html#errorpages. Since you're in a subdomain, you might have to create a set of error documents (error pages) under sfkornyek/. Try getting the smtp.php working and see if you still need a custom 404.
« Last Edit: September 25, 2017, 04:51:06 AM by MrPhil »
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline Bandi

  • Space Explorer
  • ***
  • Posts: 6
Re: Frustrated with PHPMailer
« Reply #6 on: September 27, 2017, 12:41:54 PM »
Frustrated with PHPMailer no longer.
PSPMail is now working although it does need cleanup and some modifications.

1. I moved PHPMailer-5.2-stable's
class.phpmailer.php,
class.smtp.php,
class.pop3.php,
PHPMailerAutoload.php
directly into my domain's root directory.home/.../public_html
which solved the majority of the problems

2. I also moved my PHPMailer script to send email using SMTP authentication to the public_html folder

======
<?php
// name of this file: LEVELkuldes.php.A PHPMailer script to send email using SMTP authentication
// based on http://www.webhostinghub.com/help/learn/email/email-from-web-page/using-phpmailer-to-send-mail
ini_set('display_errors',1); 
error_reporting(E_ALL);
// take out previous 2 lines after all corrections

// $from_name, $newaddress, $email and $message are the data
// submitted to this script from the html contact form
$from_name = $_REQUEST['from_name']  ;
$newaddress = $_REQUEST['newaddress'] ; // 2nd text area message from user - not yet handled
$email = $_REQUEST['from_postafiok'] ; //  user's email address
$message = $_REQUEST['message'] ; // text area message from user

date_default_timezone_set('Etc/UTC');

require("PHPMailerAutoload.php");

$mail = new PHPMailer();

// set mailer to use SMTP
$mail->IsSMTP();

//Enable SMTP debugging. Remove after tests
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
// Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

$mail->Host = "europa.lunarpages.com"; // specify outgoing server > europa is my server's name

$mail->SMTPAuth = true; // turn on SMTP authentication

// When sending email using PHPMailer, I have to send from a valid email address with password
$mail->Username = "xxxxx@szabadsagharcos.org"; // SMTP username
$mail->Password = "xxxxxxxx"; // SMTP password

// $email is the user's email address specified
// on the contact html form. This variable is set at the top
$mail->From = $email;

// set the email address that the email will be sent to.
$mail->AddAddress("xxxxx@comcast.net", "Andrew Rekay");

// set word wrap to 50 characters
$mail->WordWrap = 50;  // so far not effective
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = "Message from CIMTAR webmail!";  // Subject line in email

// $message is the user's message typed in
// the contact form. This variable is set at the top
$mail->Body = $message;  // another message $newaddress is not yet taken care of
$mail->AltBody = $message;  // what is AltBody? Can this be used for $newaddress?
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>
======

3. The html contact form that the user fills out and submits email data to PHPMailer scrip is in my home/.../public_html/sfkornyek/ folder

4. Lunarpages internet files in several places mention outgoing server name as mail.domain.com. Such as
in https://lunarpages.com/hrf_faq/what-are-the-settings-for-email/

Forget it! That does not work. The correct name is your_server_name.lunarpages.com. In my case europa.lunarpages.com. See https://support.lunarpages.com/knowledge_bases/article/5

5.Problems left for which I hope to get an answer

a. I have a second message submitted from my html form as $newaddress = $_REQUEST['newaddress'] ; How do I handle it within the php script?

b. $mail->WordWrap = 50 in the php script. It does not wrap at all. I receive continuous lines

6. Lunarpages should obviously provide detailed examples for PHPMailer, the most common mailing script today. Like other providers do.
Instead they still recommend FormMail which no longer works or at least does not work correctly on their servers

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6230
Re: Frustrated with PHPMailer
« Reply #7 on: September 27, 2017, 02:15:26 PM »
4. $mail->Body and $mail->AltBody might one be for HTML-formatted message body, and the other for plain text (tags stripped out)?

5a. In the contact form or wherever someone enters their information, what is the input field "newaddress" labeled as being? That would give a clue as to what it is for. It sounds like $mail->AddAddress() is who is receiving (at your shop) the email, $mail->UserAddress is who is officially sending the email (from your shop), and $email is what the customer/visitor claims is their email.

5b. I have no idea what's going on with WordWrap.

6. Lunarpages normally doesn't do support for Third Party applications such as PHPMailer. They expect you to go to the application's support site (https://github.com/PHPMailer/PHPMailer and https://github.com/PHPMailer/PHPMailer/wiki/). I could see that unusual configuration of your server might not be covered by PHPMailer's documentation, but there ought to be some place where you can ask questions of PHPMailer's author(s) or of its community ("issues" for bugs, Stack Overflow for questions).
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline Bandi

  • Space Explorer
  • ***
  • Posts: 6
Re: Frustrated with PHPMailer
« Reply #8 on: October 15, 2017, 02:41:33 PM »
I was under the impression that I solved all of the problems.

After some of my emails were accepted, Comcast stopped accepting my emails and sent a message with error code DM000001. Comcast explains: "...The sending domain has published a DMARC reject policy and this message has not passed either DKIM or SPF authentication for the domain..."

I wote 4 times to "[Lunarpages Online HelpDesk] [WQ67TW50DBD1" on the subject of undelivered emails without getting a reply. ... (Been a customer for a decade+) Correction. After 10 days silence they did answer. But not with a solution.

LunarPages wants us to use SSL security, e.g. https://support.lunarpages.com/knowledge_bases/article/5?fallback=true
No mention of TLS.

So I tested it:
//Set the encryption system to use tls
$mail->SMTPSecure = 'tls';
Consequently Comcast is now accepting my emails.

Draw your own conclusion regarding LunarPages today

 

Share |