?
Solved

PHP mail() not working on Host server

Posted on 2004-04-19
8
Medium Priority
?
3,743 Views
Last Modified: 2013-12-13
Help.

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.
0
Comment
Question by:ahlex70
8 Comments
 
LVL 6

Expert Comment

by:CosminB
ID: 10867035
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 http://www.php.net/imap
0
 

Author Comment

by:ahlex70
ID: 10869732
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.
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 10870547
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:movemedia
ID: 10871190
There is a way to get around using your host's SMTP server altogether with PHP.

Install PEAR (details at http://pear.php.net), then install the mail package at http://pear.php.net/package/Mail

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

-Chris
0
 

Author Comment

by:ahlex70
ID: 10871210
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.
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 10871244

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
0
 
LVL 27

Accepted Solution

by:
skullnobrains earned 2000 total points
ID: 10876470
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.
http://docs.markwest.me.uk/phpxref/pn80/nav.html?system/Mailer/pnincludes/class.smtp.php.html

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 wanadoo.fr 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.
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 10876895
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;}

include('dest.php');

//BEGINNING OF COMMUNICATION
$test= new SMTP;
$test->smtp();
if(!$test->connect('smtp.wanadoo.fr'))err('conn');
if(!$test->hello('smtp.wanadoo.fr'))err('hello');
if(!$test->mail('expediteur@wanadoo.fr'))err('mail');
if(!$test->recipient('whoever@wanadoo.fr'))err('recpt');  // call the method several times.

//SIMPLE MAIL CONSTRUCTION
$boundary = "UNDELIMITEURQUIJELESPERENESERAPASPRESENTDANSLEMAILMEMEPARHASARD";

//---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: \"http://www.yoursite.com/\"\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.

//---SEND THE DATA AND QUIT
if(!$test->data($msg))err('data');
if(!$test->quit())err('quit');

--------------------------------------------------------------------------------------------------------
if you copy-paste the source as i did, this should be usefull as well to stip line numbers. no comments.
$fo=fopen("original.php",r);$fd=fopen('dest.php','w+');while($line=fgets($fo))fputs($fd,substr($line,6));
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question