NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
PHP Mail Function not working


Joined: 01 May 2015
Posts: 10
Reply with quote
When I execute the following test script:

<?php
error_reporting(E_ALL);
$to = 'WyleySam@comcast.net';
$subject = 'Testmail';
$message = 'Hello. This is a test.';
$headers = 'From: John Doe <john.doe@example.com>';
$RetVal = mail($to, $subject, $message, $headers);
Echo $RetVal

?>

I get the following error: SMTP server response: 550 5.1.0 Authentication required

My php.ini file looks like:
[mail function]
; For Win32 only.
;smtp_port = 465
smtp_port = 587

; For Win32 only.
sendmail_from = WyleySam@comcast.net

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =



Can any one please help???
View user's profileFind all posts by WyleySamSend private message
Guru master

Joined: 24 Jul 2009
Posts: 732
Reply with quote
This probably isn't the best forum for query; you won't see many PHP coding queries here, just things relating to Nusphere products. Somewhere like stackoverflow.com might be better for you.

PHP on many web servers is pre-configured so that it can send email from web sites. When you setup your own development server, it is more likely you will have to configure email sending yourself.

On Windows web servers, PHP mail() uses an SMTP email server, which can either be the same server or a third party server. However, whilst php.ini lets you set an SMTP server and port, it does not let you set authentication. It is common for the local web server to also be an SMTP server and be enabled for relaying messages from the local server without authentication.

On Linux, PHP mail() uses the Linux sendmail utility and that passes emails off to the Linux email system, so SMTP is not used by your PHP application.

I'm guessing you are testing from Windows, because PHP mail() should not return an SMTP server error when using Linux sendmail.

If you are using a third-party SMTP server that requires authentication, then you will probably need to use a PHP mailer library such as Swiftmailer or PHPMailer. Both are easy to use and are often included with various frameworks. When you use a PHP mailer library, you can specify the SMTP server, username and password.

PEAR also has a PHP mailer, but personally I don't like using PEAR.

If you do have a local SMTP server on your test web server, then it may need configuring to relay messages without authentication, but that must be done with care because you don't want to end up with it being an 'open relay'. You want it to only relay local messages.

Overall, PHP mail() is reasonably okay for sending email and tends to work fine on most web servers for simple messages. For more complex messages, it can be problematic unless you use a PHP mailer of some sort to get the message into a good condition before sending.

At any rate, if you need SMTP authentication then you will need a PHP mailer.

If you are new'ish to PHP, then for new projects consider finding a PHP framework that you are happy with. There are loads of them available, just a matter of what you're happy with. Laravel, Zend, Symfony, Phalcon, Yii, ExpressionEngine, etc. They contain lots of functionality to make it easier to build web sites or PHP applications. Probably all of these have built-in mailing functions.
View user's profileFind all posts by plugnplaySend private message


Joined: 01 May 2015
Posts: 10
Reply with quote
Thank you for your response.

I was under the impression that PHPEd was self contained. It has it's own server & MySQL. The code I supplied above works in Dreamweaver & when run from my localhost. It does not run when using PHPEd which is why I posted here and not someplace else.
View user's profileFind all posts by WyleySamSend private message
Guru master

Joined: 24 Jul 2009
Posts: 732
Reply with quote
PhpED comes with a PHP server called SRV. It is not a web server, but it is full PHP and does everything any other PHP should do. Just like any other PHP, it might need configuring for some things and it has its own php.ini and modules. PhpED does not come with a special version of PHP, it is normal PHP.

Whilst SRV is capable of running some web projects, there are differences between SRV and a web server (eg Apache) that may mean it is better to use a real web server. Some would say that SRV is better for CLI projects.

Irrelevant of which PHP you are using, nothing changes the fact that PHP mail() cannot authenticate to an SMTP server. Your port 587 is on some SMTP server which I assume is localhost (although 587 on localhost is unusual) and is not allowing you to connect. The error response 550 is originally from an SMTP server, it is not from PhpED or PHP.

If a mail server is being used and it configured to relay for either a fixed IP address or 127.0.0.1, then the SMTP connection from PHP probably needs to use the same address as the relay. If the relay is set to 127.0.0.1, which is common, then your PHP is connecting using a fixed IP address, that would probably be enough to cause authentication failure.

Is Dreamweaver running the PHP code directly, or is it running the code through a PHP server? I stopped using Dreamweaver for PHP development years ago, but it didn't use to run PHP itself, it used to require a server, just like PhpED. Is Dreamweaver running through a PHP server that is configured so it can email? Maybe you can tell PhpED to use the same server?

PhpED does not come with MySQL. It does come with some MySQL integration and profiling capabilities, but you need to install MySQL yourself, or use a XAMPP/WAMP distribution.
View user's profileFind all posts by plugnplaySend private message


Joined: 01 May 2015
Posts: 10
Reply with quote
I use the XAMPP package to set up my localhost and PHP is running through it. I am retired now and only have a few customers left which is why I still use Dreamweaver. I use Windows Live Mail as my mail client.

This is all started when I was unable to send email using Dreamweaver & directly from my a php file on my localhost (XAMPP). I contacted Comcast and they told me to change the port from 465, which used to work fine, to 587. After doing that I was able to send EMail using Dreamweaver & from my local host.

I'm still don't understand how I can send email from Dreamweaver & from my localhost but not from within PHPEd. Since you say the the 550 error comes from the SMPT server I guess I'll contact Comcast again.

Thanks for your help.
View user's profileFind all posts by WyleySamSend private message
Guru master

Joined: 24 Jul 2009
Posts: 732
Reply with quote
So does that mean PhpED is using NuSphere SRV or is it using your XAMPP server?

If PhpED is also using your XAMPP server (use phpinfo to check) then you should find email sending works the same as when you are using Dreamweaver.

The php.ini snippet that you showed does not include an SMTP server, which means it is probably defaulting to localhost and not Comcast. You possibly need an SMTP setting:

Code:
[mail function]
; For Win32 only.
SMTP = smtp.server.goes.here
;smtp_port = 465
smtp_port = 587

; For Win32 only.
sendmail_from = WyleySam@comcast.net


Some service providers do not require authentication for sending email under specific conditions, such as when you have a internet connection direct to them.
View user's profileFind all posts by plugnplaySend private message


Joined: 01 May 2015
Posts: 10
Reply with quote
I must be running from the NuSphere SRV server and not my localhost because when testing I disabled my localhost.

I added SMTP = smtp.comcast.net to all php.ini files in the PHPEd folder - still am getting same error.

Does sendmail_path have a value to it??? If so do you know what it is??? The sendmail_path in the XAMPP php.ini points to "\"C:\XAMPP\sendmail\sendmail.exe\" -t", but I have no idea what mail program PHPED uses. XAMPP has commented out http://php.net/sendmail-path. I'll try that on Monday. I'm taking a day off on Sunday.

Once again thanks for all your help.
View user's profileFind all posts by WyleySamSend private message
Guru master

Joined: 24 Jul 2009
Posts: 732
Reply with quote
Normally Windows PHP does not use the sendmail settings in php.ini and it ignores those settings. There is a way of getting Windows PHP to use sendmail settings, which means even on Windows you can use a sendmail replacement. That C:\XAMPP\sendmail\sendmail.exe looks like your XAMPP is using a sendmail replacement.

The SMTP settings for sendmail.exe may be passed in on the command line (the bit where the -t is) or by a configuration elsewhere, maybe even in php.ini

PhpED does not use a mail sender because it simply provides you with a ready to go PHP server called SRV. You may still have to configure that PHP server if you want to use it with certain features. The NuSphere SRV server does not come with a sendmail replacement, although your XAMPP sendmail replacement would likely work with it, but you will have to configure it.

At the moment SRV is missing those sendmail settings and attempting to use SMTP. If you are using the sendmail replacement that I am thinking of, those SMTP settings are in c:\xampp\sendmail\sendmail.ini but SRV is not attempting to use the sendmail replacement.

My recommendation is to use your XAMPP server with PhpED - for web development the majority of PhpED developers either use XAMPP, or IIS with PHP.

I use a variety of development IDE's other than PhpED and in my case I have a few XAMPP and real Linux servers for different versions of things. I use those servers for all web projects and only use NuSphere SRV with PHP CLI projects. Irrelevant of the IDE, all of the XAMPP servers behave consistently; PhpED and other IDEs do not have any impact on how those servers work.
View user's profileFind all posts by plugnplaySend private message


Joined: 01 May 2015
Posts: 10
Reply with quote
I have no idea how to use the XAMPP server with PhpED.
I've added SMTP = smtp.comcast.net to the php.ini

Comcast cannot help. According to them since I can send/receive email thru Windows Live Mail there is nothing they can do.

I read somewhere on the internet that PEAR should me installed - it wasn't. There is no PEAR directory in D:\Development\PHPEd\php54, which is the directory the php.ini file is in. PEAR is now installed in C:\Users\NeilSwartz\AppData\Roaming\PEAR. I know nothing about PEAR!!!

The registry entries for PEAR are:
"PHP_PEAR_SYSCONF_DIR"="C:\Users\NeilSwartz\AppData\Roaming\PEAR"
"PHP_PEAR_INSTALL_DIR"="C:\Users\NeilSwartz\AppData\Roaming\PEAR\pear"
"PHP_PEAR_DOC_DIR"="C:\Users\NeilSwartz\AppData\Roaming\PEAR\docs"
"PHP_PEAR_BIN_DIR"="C:\Users\NeilSwartz\AppData\Roaming\PEAR"
"PHP_PEAR_DATA_DIR"="C:\Users\NeilSwartz\AppData\Roaming\PEAR\data"
"PHP_PEAR_PHP_BIN"="D:\Development\PHPEd\php54\php.exe"
"PHP_PEAR_TEST_DIR"="C:\Users\NeilSwartz\AppData\Roaming\PEAR\tests"

Still getting the same error: Warning: mail(): SMTP server response: 550 5.1.0 Authentication required.
View user's profileFind all posts by WyleySamSend private message
Guru master

Joined: 24 Jul 2009
Posts: 732
Reply with quote
You don't need to know anything about PEAR - I don't think you need PEAR. I've never used PEAR for sending email; there are better methods. I believe some (or all) of the PEAR packages are no longer maintained. Many of them will still work with newer PHP.

I've already mentioned this previously, but I'll be a little more consise here:

* It looks like your existing XAMPP is using a sendmail replacement; it is not using the SMTP settings in php.ini

* Your sendmail replacement probably gets it SMTP settings from c:\xampp\sendmail\sendmail.ini - it does not get its SMTP settings from php.ini

* With PhpED, you are trying to use the built-in web server SRV with SMTP settings from php.ini - it is probably not going to work and if the comcast email server requires authentication (username & password) it might even be totally incapable of working using php.ini SMTP settings.

* My recommendation is to use your XAMPP with PhpED.

The PhpED project wizard asks a few questions so it understands where the web site files are stored on disk and which web server you are using. If you are using a local XAMPP then that is the Local server option.

If your XAMPP server is running, then you can access web sites using a URL such as http://localhost/mywebsite

For an existing project, all you have to do is tell PhpED what that URL is, using the Project Properties > Run Target.

In those settings you will set the Run target to Local server, then set the web site address in Root URL. In your case it might be something like http://localhost/mywebsite

If you are wanting to run whichever file is currently open in the PhpED editor, then leave the Default file or URL blank.

If the web site is capable of running through your XAMPP, then it will work with PhpED. Debugging is another step, you have to installed the NuSphere debugger DBG into your XAMPP, but getting the site running would be the first step.

You can use the NuSphere Debugger Wizard to assist with installing DBG into your XAMPP. http://www.nusphere.com/products/dbg_wizard_download.htm
View user's profileFind all posts by plugnplaySend private message


Joined: 01 May 2015
Posts: 10
Reply with quote
I went to http://www.nusphere.com/products/dbg_wizard_download.htm and pressed the Download Now button. The screen displayed text when I did a Save As it saved the text to a file named dbg-wizard_php.mht (have no idea what a mht file is). I moved the file to my localhost root dir (http://localhost/) and tied to execute it as mht & after changing the extension to php. All I got was text displayed on the screen.

I have no idea what is going on. I am a beginning PHP programmer and some of this stuff is greek to me!!!

All I know is everything worked correctly 6 months ago when I last used PHPEd. I've also copied to problem php script to several websites on the lan and it worked correctly.

Once again thanks for trying to help. You must be frustrated with me.
View user's profileFind all posts by WyleySamSend private message
Guru master

Joined: 24 Jul 2009
Posts: 732
Reply with quote
Don't save the file as an MHT because that is an archive format for Internet Explorer, it does not the original text for the PHP file. When you later rename the file to PHP, the file still has incorrect contents because it has already been converted to MHT.

Go back to the download page, click Download File, do a Save As and use Text File. That should give you the original unmodified file.

Maybe last time you used PhpED, you used it with a XAMPP server? This time on your 3-May reply you hinted you were using PhpED with SRV and that would be the default if you had just installed PhpED.

If you're script emails correctly through your XAMPP server, then using your XAMPP server with PhpED will also email correctly.
View user's profileFind all posts by plugnplaySend private message
PHP Mail Function not working
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 2  

  
  
 Reply to topic