Solved

PHP mail() not working on Host server

Posted on 2004-04-19
8
3,719 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 26

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 26

Accepted Solution

by:
skullnobrains earned 500 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 26

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 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