Solved

PHP mail() not working on Host server

Posted on 2004-04-19
8
3,714 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 29
WooCommerce Sort by Date 4 9
.htaccess file settings 4 35
Wordpress Body Class 5 11
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now