Setting SMTP in php.ini to make mail() function work

with these 3 use statements:

use "..\PHPMailer-master\src\PHPMailer";

use “…\PHPMailer-master\src\SMTP”;
use “…\PHPMailer-master\src\Exception”;

i get this error:

Very odd, it is like it is not using the …

Try it with just the \ In other words:

use "\PHPMailer-master\src\PHPMailer";

If not, I will have to upload it to my Godaddy server and test it for you there… Odd, it should work this way!

i get the same error Ernie, but now it says unexpected ‘"\PHPMailer-master\src\PHPMail’" instead of unexpected "…\etc, etc…"

do you wanna know what godaddy told me to do regarding an spf record setting on DNS?

I just read on this a bit. Seems that the version we both downloaded uses just the PHP files. If so, the USE command is not useful. You might need to just include the files directly like this:

include "..\PHPMailer-master\src\PHPMailer.php";
include “..\PHPMailer-master\src\SMTP.php”;
include “..\PHPMailer-master\src\Exception.php”;
...

Ernie, I was hoping that last post of urs would let us progress on this, but now I get a boat load of errors and they’re all different than before:

That is progress. Show me the first two or three errors… It did not post them…

Wait, it did when I refreshed… Hold on…

remove the … from the start of each.

I removed the “…” 3 periods in front of the file paths on each line and I get the same amount of errors in my last image.

I have uploaded the library and test code to my server.
I also have errors, but, found out why. Hold on a couple minutes so I can find a fix for you.
Sorry for all the delays. It is a messed up code set up in their library…

Just a couple minutes…

could it be, Ernie, that answer #3 in this following post is true for us??

I solved it, but, one small error left to fix on the SMTP part.
Seems that PHPMailer changed it’s setup about a year and a half ago.
(Did not know that!)
I got it working, just one minor this to fix and I will report the needed changes…

Okay, vba_php, I got it working as far as the overhead items go. First, I had to alter the path’s involved and also had to make some minor changes in the includes. (Changed them to require’s which are basically the same thing, but, it matches their samples better that way. Also, a minor change in the path names to make it all work. First thing is rename the folder named “PHPMailer-master” to just “PHPMailer” as it is used inside the code in the library. And, here are the updated parts:

ini_set(‘include_path’, ‘PHPMailer’);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require “…/PHPMailer/src/PHPMailer.php”;
require “…/PHPMailer/src/SMTP.php”;
require “…/PHPMailer/src/Exception.php”;

( Hmmm, there are two periods before the slash in the requires. For some reason, this site shows three dots for those. Must be dot-dot-slash… )
So, that will get the library working. I tested it from a file inside a folder named php and it works for me. I did not alter the actual mailing code as in the sample code they post for you. You will need to go thru each and remove unneeded lines. Like if you do not need attachments, remove those lines. Also, Godaddy quite often needs the FROM email field to be from your server. If it fails let us know and we can sort that out for you. Hope this works!

good work! 1 error left, and I think it’s obvious. here it is:

perhpas it’s looking for the PHPMailer.php file in the default ROOT dir (parent dir of my “domain name dir” of my hosting account, which is “public_html”?? the error is for code line:

$mail = new PHPMailer(true);

ODD ! That line works on my test files.

So, we are very close! Recheck the setup lines to make sure they match these:
ini_set(‘include_path’, ‘PHPMailer’);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require “…/PHPMailer/src/PHPMailer.php”;
require “…/PHPMailer/src/SMTP.php”;
require “…/PHPMailer/src/Exception.php”;

// Instantiation and passing true enables exceptions
$mail = new PHPMailer(true);
( ONLY two periods on the requires… )
I am wondering if one is spelled wrong. And, you did rename the PHPMailer folder, right?

Oh and FYI… The server you are using is a shared server and holds the data under various subfolders. The HOME-PUBLIC-HTML location in the error message is basically just your ROOT folder. It is a normal display error, nothing odd… It should include your domain-name and I see you blanked that out. All good. Never give personal details or passwords on any blog. Once we get past that error, you still have to set up all the SMTP email options. There are a ton, but, not all are needed. Actually only a few are needed.

yes i renamed the PHPMailer folder. do you really want me to include the 3 “use” statements? I thought u said they were the problem? by including the 3 “use” statements and 3 “require” statements and enclosing all the paths in double quotes, which is what I have to do so Eclipse does not throw an error, I get a parse error, with PHP stopping on the first “use” statement:

Parse error** : syntax error, unexpected '"PHPMailer\PHPMailer\PHPMailer'

and by the way, the name is Adam, not php_vba. :grinning:

Well, the USE command does not have (use) quotes. And, it does need the three of them for some reason! Another ODD thing. Perhaps I can ask one of the other more experienced programmers here tomorrow when I get some rest and get a reason why.

So, use the same setup I posted a couple ago…

Ernie,

When I first told godaddy about the spamming out problem using mail(), a higher up level agent told me to add an spf in my DNS setting to fix it: Add an SPF record | Domains - GoDaddy Help US

they also gave me a help article on how to setup and send mail using PHPMailer: Solved: Sending email by PHPMailer using PHP mail not SMTP - GoDaddy Community

another thing the level 2 agent told me to do after I told him I was getting an error using “smtp.mydomain.com” was to ping that address through the windows DOS prompt. this message resulted:

ping%20smtp%20server

Sponsor our Newsletter | Privacy Policy | Terms of Service