Page 1 of 1

PHP mail problems.

Posted: Tue Aug 21, 2007 2:18 am
by henrygao
twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


dear friends:

Recently i moved my application from linux enviroment to windows2003 enviroment. everything is ok but mail function.

after i setup mail server in windows, i tested it by sending a email to support@mydomain.com and i can receive it. and I also login to my domain email and send email via support@mydomain.com also ok.

--------------

but the problems: all the system email related fnction not (which they works in linux enviroment). 

the code for tell frined function like below:

Code: Select all

$headers .= "From: {$in['YouEmail']}\r\n";
  $headers .= "To: {$in['Email']}\r\n";
  $title .= "Your friend {$in['UserName']} sent your this link";
  if(@mail($in['Email'], $title , $tmp . $in['Content'], $headers))
  {
   $Info = new Info('Email was sent successfully! Your friend will receive your email soon!.', 

_PHP_SELF . '?act=login', $tpl);
   
   $tpl->set_currentfile('main');
   $tpl->set_var('DATA', $Info->Show());
  }
  else
  {
   new Error('Fail to send email, please contact admin to check email server configration.', 

'', _CurrentURL, $tpl); 
  }
after execution of the code, it gives error "fail to send email...".

however, only one function works which is feedback function, the code as below:

Code: Select all

$tpl->set_var('Title', $in['Title']);
    $tpl->set_var('Sender', $in['Sender']);
    $tpl->set_var('Email', $in['Email']);
    $tpl->set_var('Content', $in['Content']);
    $tpl->set_var('SenderIP', ip2long($in['REMOTE_ADDR']));
    $str = $tpl->parse('mail');
    
    $headers .= "From: domain.com <support@domain.com>\r\n";
    $headers .= "To: domain.com <support@domain.com>\r\n";

    @mail("support@domain.com", SYS_NAME . $title, $str, $headers);
   }
It really makes me confused how it happens? Is there any expert can advise some suggestion? [s]Pls[/s] Please help... thank you


twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 21, 2007 3:45 am
by volka
please try

Code: Select all

...
$headers .= "To: domain.com <support@domain.com>\r\n";

foreach( array('SMTP','smtp_port','sendmail_from','sendmail_path') as $p ) {
	echo $p, ': ', ini_get($p), "<br />\n";
}

$retval = mail("support@domain.com", SYS_NAME . $title, $str, $headers);
var_dump($retval);
and post the output

Re: PHP mail problems. Expert, pls help..please

Posted: Tue Aug 21, 2007 7:13 am
by superdezign
henrygao wrote:twigletmac
There's a mod you don't see everyday.


PHP's native mail() function has difficulties on some servers, as many paranoid hosts disable it (usually only for shared hosting). You could try SwiftMailer and utilize one of the different methods.

Re: PHP mail problems.

Posted: Wed Aug 22, 2007 3:07 am
by henrygao
superdezign wrote:
henrygao wrote:twigletmac
There's a mod you don't see everyday.


PHP's native mail() function has difficulties on some servers, as many paranoid hosts disable it (usually only for shared hosting). You could try SwiftMailer and utilize one of the different methods.
hi superdezign: which mod your refer to? actually this is dedicated server and I have control on config file. and one more strange thing is, when I use feedback function, it does work. so that mean somehow the email server is fine. but all the rest email function not working...very strange.
[s]pls[/s] please adviser further. thank you
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Wed Aug 22, 2007 3:26 am
by henrygao
volka wrote:please try

Code: Select all

...
$headers .= "To: domain.com <support@domain.com>\r\n";

foreach( array('SMTP','smtp_port','sendmail_from','sendmail_path') as $p ) {
	echo $p, ': ', ini_get($p), "<br />\n";
}

$retval = mail("support@domain.com", SYS_NAME . $title, $str, $headers);
var_dump($retval);
and post the output
Dear volka: i have tested as you suggested, the output like below:
for the feedback function which i mention is working, the out is:
SMTP: localhost
smtp_port: 25
sendmail_from:
sendmail_path:
bool(false)

for the rest of function which i mention is not working, output as below(actually is same as above)
SMTP: localhost
smtp_port: 25
sendmail_from:
sendmail_path:
bool(false)

i cannot see anything wrong as first one working but second not. pls advise further. thanks alot

Posted: Wed Aug 22, 2007 4:59 am
by volka
henrygao wrote:for the feedback function which i mention is working, the out is:
SMTP: localhost
smtp_port: 25
sendmail_from:
sendmail_path:
bool(false)
the smtp server at localhost:25 is either not running or does not accept the mail.
please try

Code: Select all

$sd = fsockopen('localhost', 25, $errno, $errstr, 5);
if ( false===$sd ) {
	die("fsockopen failed. $errstr ($errno)");
}

echo fgets($sd);
fwrite($sd, 'quit');

new findings

Posted: Wed Aug 22, 2007 5:12 am
by henrygao
thanks for [s]ur[/s] your info. but i just have a new finding and hope this may give some clue on this issues.

@mail($in['Email'], $title , $tmp . $in['Content'], $headers)

only works if $in['email'] is support@domain.com or sales@domain.com (i only configed this two mail), all the rest (etc abc@mai.com or abc@domain.com) all not working.

is these any config file i need to change?
many thanks
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Wed Aug 22, 2007 5:18 am
by henrygao
volka wrote:
henrygao wrote:for the feedback function which i mention is working, the out is:
SMTP: localhost
smtp_port: 25
sendmail_from:
sendmail_path:
bool(false)
the smtp server at localhost:25 is either not running or does not accept the mail.
please try

Code: Select all

$sd = fsockopen('localhost', 25, $errno, $errstr, 5);
if ( false===$sd ) {
	die("fsockopen failed. $errstr ($errno)");
}

echo fgets($sd);
fwrite($sd, 'quit');
hi volka:
the output for this is
"220 localhost ESMTP "
i have no ideas on that. any suggestion? thanks a lot

Posted: Wed Aug 22, 2007 5:23 am
by volka
A smtp server can (and should) be configured to accept only mails from certain accounts. But that depends on the mail server you're using.
You might be interested in http://swiftmailer.org/ and viewforum.php?f=52
Personally I'm not too happy about scripts that send emails with arbitrary "from:" addresses. Is there any mechanism to prevent abuse in your script?

Re: PHP mail problems.

Posted: Wed Aug 22, 2007 6:30 am
by VladSun
//offtopic
henrygao wrote: Recently i moved my application from linux environment to windows2003 environment.
I am just curious what makes you do that? I am really interested to know your major reasons for doing that.