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

No, you do not need an SSL cert. That is something else.
What is the current SMTP error you are getting. It should have a number like #220 or #500, etc…

this is the error I get. It has no so number:

2019-11-25 18:01:00 SMTP ERROR: Failed to connect to server: (0)

also, godaddy says that port 465, which is what i’m using, IS a secure SMTP port and that it IS open. so no issue there.

Okay, I did some research since you appear to want to stick with SMTP instead of POP3.
I found one person who said you need to use the localhost instead of your mail.host.com.
They said to use:
$mail->isSMTP();
$mail->Host = ‘localhost’;
$mail->Port = 25;

In another place, I found this for the setup. Note that the host is the actual mail server that Godaddy gives you in the control panel. In the control panel there is a connect example for emails and in there, you will find the correct version of “secureserver” address that is where your mail server is set to.
$mail->isSMTP();
$mail->SMTPDebug = 0; // for production use, but set to 3 for debugging
$mail->Host = ‘n3plcpnl0012.prod.ams3.secureserver.net’; //my specific shared server
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPSecure = ’ ';
$mail->Username = ’ ';
$mail->Password = ’ ';

    $mail->SMTPAutoTLS = false; // Prevents opportunistic TLS encryption

Since you are not even connecting to the mail server (not your hosting web server), I am guessing that you have the incorrect host listed. In the second example, they say not to set the secure,user,pass options. Set them to nothing… ‘’ They said it was due to this:

The thing that got it working for me is setting SMTPAutoTLS to false (final line of code), as the shared servers do not have a valid SSL/TLS certificate and so are rejected by the mail server.

I would say try both of these and if not working, you would need to talk to Godaddy as something must be wrong with your SMTP setup.

Okay, I spent some time at Godaddy for you. In my control panel, I went into the email list which shows all your email accounts. Once there, on the right side it has a button for “setup email center”. Go there and it asks you which account and how you want to configure it. Select “other” instead of Outlook. Then, click next and it will show you your email hosting account. Somehow mine is “smtpout.asia.secureserver.net
which is odd as my server must be in Asia… Don’t understand why… Anyway, as you see, my Godaddy
SMTP server is clearly marked and I would need to put that into my PHPMailer code if I used SMTP.

Hope that helps!

1 Like

I will try both of the code updates you gave, and I will look in the godaddy email hosting account settings and see what the smtp server is that’s listed, then I will try the script again with that in the "$mail->Host = " line. Give me about 30-60 minutes. i’ll get back to you. thanks for all of this so far! I hope my ignorance hasn’t ticked you off!

Never get ticked off while helping a fellow programmer solve a problem.
I am sure you are close to a solution. Just really think it is the connection to the mail server…
We will solve it. Take your time.

ok, here are the result from the 3 attempts I made:

attempt #1:

code used:

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”;

//Create a new PHPMailer instance
$mail = new PHPMailer(true); // Passing true enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ‘smtpout.secureserver.net’; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘[email protected]’; // SMTP username
$mail->Password = ‘password’; // SMTP password
$mail->SMTPSecure = ‘ssl’; // Enable TLS encryption, ssl also accepted
$mail->Port = 25; // TCP port to connect to

//Recipients
$mail->setFrom('[email protected]', 'Corporate');
$mail->addAddress('[email protected]', 'Adam');     // Add a recipient
$mail->addReplyTo('[email protected]', 'Adam');

//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Message has been sent';

} catch (Exception $e) {
echo '

Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

the above resulted in this error:

Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

attempt #2)

code used:

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”;

//Create a new PHPMailer instance
$mail = new PHPMailer(true); // Passing true enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ‘p3plcpnl0398.prod.phx3.secureserver.net’; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Enable SMTP authentication
$mail->Username = ‘’; // SMTP username
$mail->Password = ‘’; // SMTP password
$mail->SMTPSecure = ‘’; // Enable TLS encryption, ssl also accepted
$mail->Port = 25; // TCP port to connect to
$mail->SMTPAutoTLS = false; // Prevents opportunistic TLS encryption

//Recipients
$mail->setFrom('[email protected]', 'Corporate');
$mail->addAddress('[email protected]', 'Adam');     // Add a recipient
$mail->addReplyTo('[email protected]', 'Adam');

//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Message has been sent';

} catch (Exception $e) {
echo '

Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

the result of attempt #2:

*Message has been sent*

And I got the email in the gmail inbox with all specs that are in my script! I didn’t even try attempt #3 cuz this worked! Hooray! Can you believe it took this long!?

Wow! Great and bittersweet as my Grandma would have said! Great cuz it is working! Bad cuz it took so long. But, very glad we BOTH stuck with it. Now you can go back and adjust it for future use. What I mean, is that you can make it into a PHP file by itself and call it sendemail.php or something and then
pass data to that file as needed and you can use it in all of your pages you need to send emails from.

Very nice! See you in your next post… ( CYA in the bitstream, cuz that is all this really is… Ha! )

Ive already have my form page script set up and the post operation code and js redirects in place and it works fine. Now i will add this to it! Btw is there anyway to officially thank u for this or mark this thread as solved?

On the previous version of this site, you could give a poster “Karma” and I had thousands of them!
But, on this version, you can click on the heart and it marks it in my list of “likes”. Not the same really.
I stopped being on this site for awhile after they switched to this version. I found it more “canned” and
did not have as many great features as the last one. But, I came back… Ha!

Your thanks are appreciated… Post another issue and I and others will help you out! Glad it is solved!

I talked to an admin on www.phpfreaks.com and he said they did the same thing over there years ago and he didn’t like it either. at any rate, I marked this thread solved. I’m sure we’ll talk again!

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?

Sponsor our Newsletter | Privacy Policy | Terms of Service