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

SOLVED IT ! ! !

VBA_php, to use SMTP, you need to send it from your “LOCALHOST” ! BUT, do not use authentication.
Anyway, do this for testing…

Create a PHP file and enter the following code into it. Change the three places that I have X’d out data.
Set the FROM and REPLY-TO both to the email account you are sending from. (This is needed for AOL, Yahoo and some other email addresses as they do not allow relaying from other accounts.
Set the ADDADDRESS to your personal address to make sure you can receive the email.
That’s it. Copy to the “php” folder on your server.
Go to the your-domain/php/mailtest.php file or whatever you called it. and it should send the email out.
NOW, notice, I turned on ALL error tracking and displays. Therefore, you will get a TON of info on the page itself when you go to it. It is just for testing so you can see all details. Of course, take that part out once it is working… Let me know if it works as-is once you get home!

> <?php
> error_reporting(E_ALL);         //  TEMP ! ! ! ! ! ! ! ! ! ! !
> ini_set("display_errors", 1);   //  TEMP ! ! ! ! ! ! ! ! ! ! !
> 
> /**
>  * This example shows making an SMTP connection with authentication.
>  */
> 
> // Import PHPMailer classes into the global namespace
> 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";
> 
> //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("America/New_York");
> 
> //Create a new PHPMailer instance using SMTP
> $mail = new PHPMailer;
> $mail->isSMTP();
> //Enable SMTP debugging
> // SMTP::DEBUG_OFF = off (for production use)
> // SMTP::DEBUG_CLIENT = client messages
> // SMTP::DEBUG_SERVER = client and server messages
> $mail->SMTPDebug = SMTP::DEBUG_SERVER;
> //Set the hostname of the mail server
> //************************ Change this to Godaddy's SMTP server from your control panel!!!!!
> $mail->Host = 'localhost';
> //Set the SMTP port number - likely to be 25, 465 or 587
> $mail->Port = 25;
> //Whether to use SMTP authentication - true=use it and then you need user/pass info,  false=not use it and should work from your server
> $mail->SMTPAuth = false;
> //Set who the message is to be sent from
> $mail->setFrom('XXXXXXXXXXXXXX The Servers Email XXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX NAME ON SERVER EMAIL OR COMPANY NAME XXXXXXXXXXXXXXX');
> //Set an alternative reply-to address
> $mail->addReplyTo('XXXXXXXXXXXXXX The Servers Email XXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX NAME ON SERVER EMAIL OR COMPANY NAME XXXXXXXXXXXXXXX');
> //Set who the message is to be sent to
> $mail->addAddress('XXXXXXXXXXXXXX EMAIL TO SEND TO XXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX NAME TO SEND TO Ernie');
> //Set the subject line
> $mail->Subject = 'PHPMailer SMTP test';
> //Read an HTML message body from an external file, convert referenced images to embedded,
> //Altered text not to you HTML template, but, instead use direct HTML layout
> $temp_HTML = <<<'EOD'
> <!DOCTYPE html>
> <html>
>     <head>
>         <title>Test Email</title>
>     </head>
> <body>
>   <h3>Test Email from Ernie...</h3>
>   <p>This is just some test email text to see if the email actually works using SMTP!</p>
> </body>
> </html>
> EOD;
> //convert HTML into a basic plain-text alternative body
> $mail->msgHTML($temp_HTML);
> //Replace the plain text body with one created manually
> $mail->AltBody = 'Test Email from Ernie...  This is just some test email text to see if the email actually works using SMTP!';
> //Attach an image file
> //$mail->addAttachment('images/phpmailer_mini.png');
> //send the message, check for errors
> if (!$mail->send()) {
>     echo 'Mailer Error: ' . $mail->ErrorInfo;
> } else {
>     echo 'Message sent!';
> }
> ?>

ok Ernie, here’s what I’ve got. The error message when running this new script of yours is:

** Parse error : syntax error, unexpected ‘<<’ (T_SL) in /home/OwnersName/public_html/DOMAIN/php/test.php on line 47**

also, I don’t know if that’s the only error, cuz in Eclipse, it is throwing 4 different errors, although 3 make no sense. But 1 of the red X’s that appear is showing the exact same error in eclipse that I’m getting when going to “test.php”. what exactly is “EOD”? I’ve never heard of it. and why are there 3 “<<<” symbols before that? I’ve never seen that symbol used in any PHP script I’ve implemented. See attached image for an example of 1 of the other 3 stupid errors being thrown by eclipse:

Well, I do not know! Eclipse? Just copy the text AS-IS to a text file and rename it to a PHP file.
Bypass the editor. My guess is you have a lot of odd settings in it. Have you ever tried NetBeans?
It is what a lot of us use for editing PHP code.

If you can copy the code AS-IS, I can send you the file. That will be in a link or private message…

Oh, also, EOD is a way to enter text into a variable directly.
You can use anything… But, you use three <<<'s then a code, normally EOD or EOT for end of data or end of text. Then, put any text you want on the next line(s) and end it with the EOD or EOT on a separate line. This tells the PHP parser to use the lines between then, <<< and EOD/EOT as full text to place into the variable. Make sense?

The name of this process is actually “heredoc”. It is basically used to enter HTML code into a variable.
Here is the php.net explaination: heredoc

when you post code here Ernie, i DO copy and paste it into a txt, cuz if i copy it into eclipse, weird junk happens. but it doesn’t matter if eclipse throws the errors or not, the errors still happen when run on the webpage and that’s unrelated to eclipse. so the problem still exists for me. so you want me to copy your code AS IS and send it to you? why? and what file r u going to send me? I don’t think I follow ur first message.

on a side note to all of this, I’ve used dreamweaver for years cuz it’s got intellisense for almost any language. eclipse is meant only for PHP i believe, and it does not have intellisense at all. if it does, i don’t have the option turned on.

I’d recommend PHPStorm by jetbrains, but you probably don’t do this enough to want to pay for something. Visual Studio Code has PHP extensions as well, but it is a text editor, not a full fledged IDE.

Heredoc is a funny and VERY temperamental thing. So copying and pasting it rarely works properly. The big things are, no space and nothing else on the line or the line below it for the closing delimiter.

Dreamweaver is a web designer app, not a PHP editor. Eclipse is an editor, but, you need to customize it for PHP. Netbeans is another famous and free editor.

What I was explaining was the posted code works as-is after you change the three email lines.
You need to copy it and put it into a file OUTSIDE of Eclipse which can not seem to handle heredoc’s.
OR, remove the heredoc part of the code and just use normal strings. Harder that way, but, does not matter…
OR, even remove the HTML parts and just use text emails. The point is that the code works and the editor is messed up. I would dump the editor if it can not allow heredoc’s. They are used a lot in the world these days for templates and the such… But, if you are comfortable with it, I can rewrite the code to not use heredoc’s.

$temp_HTML = "<!DOCTYPE html><html> <head> <title>Test Email</title> </head> <body> <h3>Test Email from Ernie...</h3> <p>This is just some test email text to see if the email actually works using SMTP!</p> </body> </html> ";

Something like this will work instead of the herdoc part…

interesting stuff here! see the image Ernie. The server is flagging it as spam and rejecting the request to send it! Regarding Dreamweaver, PHP is part of web applications. which is prolly why DW has intellisense for it. I love DW and will always use. I have no damn idea I downloaded Eclipse. It really does suck. I will check out the apps mentioned by both of you.

That does not say it is SPAM…
It say it is not making the connection to the SMTP server. Dreamweaver will let you edit PHP and it allows heredoc’s. But, it is not a real programmer’s PHP editor. Netbeans is.
What is nice about a real programmer’s editor is that is shows up missing ending braces { } and missing

's , etc. It is more handy when debugging, too. Lots of things you can do with it that is not available in a non-programmer editor like Dreamweaver. I would not use Netbeans for designing web pages as it is not as easy for that.

Now, did you copy my code AS-IS to a file and run it on your server under the “php” folder?
Or did you copy paste it as before?

What STMP server are you attempting to connect to?

Godaddy’s smtpout.secureserver.com

He has the same shared server that I do and my code works AS-IS.
His keeps throwing out errors. But, his editor also keeps messing with the text.

Vba_php, do this…
create a file with just this one line.
phpinfo();
And, move it to your server.
Run it.
Look down the displayed page for CORE section.
In there, look down to the SMTP and SMTP-PORT sections. Tell us what they both say.
Thanks!

SMTP	localhost	localhost
smtp_port	25	25

in my last attempt Ernie, I eliminated your heredoc code (the 2 sections where EOD appeared) and substituted in the HTML markup you gave me and assigned it to the var ‘$temp_HTML’

Try this…
In the code, for the host, use: relay-hosting.secureserver.net instead of localhost.
This is Godaddy’s extra email server for relaying SMTP out from their shared servers.
It should still use port 25.

got the following error:

2019-11-27 18:01:15 SMTP ERROR: Failed to connect to server: Connection refused (111)

Hmmm…

I would put it back to localhost and contact Godaddy. I would call them, not email or chat.
I feel a bit stumped as it should be easier than this!

Try going to your cPanel Page

Look for “Mx Entry” Click it then set it to “remote”

Then go to “PHP Processes” hit “Kill prcesses”

Astone, what does the remote Mx entry do? Never needed to alter that before.

Sponsor our Newsletter | Privacy Policy | Terms of Service