PHP mail() not working on Host server


I am new to php and web development, so please bear with me. I am trying to send an email from my webiste. To test the functionality of the SMTP server with My webhosting company I have tried to use the "mail()" function. I do not receive the test email though. I think that the smtp server requires authentication, so I tried to use "fsockopen()", but that did not work either.

The web hosting co is IXWebhosting. I running on their Windows NT server. Any suggestions on what to try?

Thanks for bearing with me.
Who is Participating?
skullnobrainsConnect With a Mentor Commented:
here is a link to a class which performs smtp authentication.
it is a simple class so there is no installation required on the server.

i did not test it, but it seems close to the RFC, and as far as i undersatnd, will output the exact error code returned by the server. all the steps are separate functions (connect,hello,authenticate,mail,data...), so debuggging should be easy.

!!! the licence is LGPL, so i guess u can use it, but better double-check.

something still is crooked : you definitely should have an error message when using the mail() function in php, if there is an authentication issue, unless the function has been deactivated.

if u can change the ini_setting, try which provides almost unlimited mail routing services.
btw, if the community of spammers could use it a little more, maybe then the over-traffic will be too huge and they'll stop providing such services... which is my goal in publicly naming them !

i need to test a few things, so i'll be downloading the class today.
i'll post information here.
open your php.ini file and change the value of "SMTP" from localhost to your SMTP server (change smtp_port  if you have too)

if this won't wrok for you you should look at the IMAP, POP3 and NNTP Functions
ahlex70Author Commented:
Hi Cosmin,

The only thing with that is that I am using a web hosting company. I have asked and cannot modify their PHP.ini file. I have also tried to use the ini_set() command to set it at runtime, but cannot do that either.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

many hosting companys simply deactivate the mail function as it would be too easy for spammers to use.

if the mail function does not output any error, and the adress is properly typed, and you don't receive it, it is probably the case.

try to retrieve the actual value of the SMTP using ini_get.
if it is empty and you are under a windows server, it is useless to try and use the mail() function.

you may try to use automation to get the mail send from outlook, assuming it probably is present on the server or rather send the mail from the client's mail client.

try the smtp server using a regular mail client.
There is a way to get around using your host's SMTP server altogether with PHP.

Install PEAR (details at, then install the mail package at

You can use this package to send mail via mail(), sendmail (*nix) or connecting directly to the recipient's SMTP server.

ahlex70Author Commented:
Hello skull,

I got the results of the PHP.ini file and they do have their stmp server enabled. I am able to use Outlook locally to retrieve my emails from their server. I am not sure whether they have Outlook on their server.

Are there any other options to try. I think the reason Outlook can retrieve the messages and send is because it does the authentication. I am looking for a script then that can do the same.

Thanks for your help.

Many times isps have settings in place to where the 'from' address must be an address present on the server or at least valid through their servers.

Test mail() using your real email address from the isp and hard code it in just to make sure.

i had a similar prob and this was the case.

hope this helps
tested the class, and it does work pretty fine
nb this is a simple test to check if it works. error handling is not acceptable on a site.

//ERROR FUNCT FOR EASY DEBUG. (need testing, i'm not sure wether it displays errors properly)
function err($fct){echo '<br>ERR<b>$fct</b><pre>';print_r($this->error);exit;}


$test= new SMTP;
if(!$test->recipient(''))err('recpt');  // call the method several times.


//---mail headers
$msg =
"From: webserver@localhost;
MIME-Version: 1.0;
Content-Type: multipart/related; boundary = \"$boundary\"
//pour les clients qui ne prennent pas en charge MIME
$msg .= "ceci est un message au format MIME 1.0\n\n\r";

//---html headers
$msg .= "--$boundary\n";
$msg .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";      //charset inutile voire néfaste ?
$msg .= "Content-Transfer-Encoding:7bit
Content-Disposition: inline
Content-Base: \"\"\n\n";//il faut 7 bits pour la compat ASCI
$msg.= "<html><body>hello world</body></html>";
$msg .= "\n\n";

$msg .= "--$boundary--\n";  //boundary is the separator. --$boundary -> new section, --$boundary-- -> end of mail.


if you copy-paste the source as i did, this should be usefull as well to stip line numbers. no comments.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.