...

View Full Version : mail func doesn't work, but fsockopen to smtp server does?!?



x_goose_x
04-15-2003, 04:01 AM
Why is it that when I connect to my smtp server using fsockopen I can send mail, but when I try to use the function "mail()" it give me an error? I have the same server/port/config in my php.ini as I do in my fsockopen script.

Err:
Warning: Unknown error in c:\apache\www\email.php on line **

My fsock code:


<?php

$sender = "some-honkey@yahoo.com";
$recv = "that-guy-there@hotmail.com";
$host = "mail.server.ca";
$port = 25;
$subj = "My email sunject";
$body = "send body...";
$connect = fsockopen ($host, $port, $error_num, $error_str, 30)
or die ("error 1");
if ( $connect ) {
print fgets ($connect, 1024);
fputs ($connect, "mail from: $sender\r\n");
fputs ($connect, "rcpt to: $recv\r\n");
fputs ($connect, "data\r\n");
fputs ($connect, "Subject: $subj\r\n");
fputs ($connect, "$body\r\n");
fputs ($connect, ".\r\n\r\n");
fclose ($connect);
} else {
print "$error_num - $error_str<br>\n";
}

?>


The mail functions I've tried using were cut and pasted from different tutorials and from people who got the exact same script to work for them, so I know it's not my syntax. My guess is that it because of the usual problem, I'm running apache on windows 2k. Could that be the source of my problem? Are there any other possible sources for errors?

Thanx.

krycek
04-15-2003, 12:08 PM
Well, I hate mail(). It is because you have to set it up and then it still is finnicky that I wrote my own mail() replacements ages ago :)

goose, stick to doing it yourself - forget about mail() :)

::] krycek [::

firepages
04-15-2003, 05:23 PM
if your php.ini entries are correct then there is no reason that mail() should not work unless your server requires authentication (which it really ought to) , that said your script does not appear to authenticate either (unless you have just removed the user and pass for understandable reasons) , if so check your php.ini again ?

to be honest I am more surprised that your script below works without a EHLO/HELO in sight!

bored
04-15-2003, 05:59 PM
I agree with firepages, the mail() function should work perfectly given the .ini settings are correct. As far as the authentication part, I just use referral entries to allow sending permissions. Makes life easier.

krycek
04-15-2003, 08:05 PM
yup, he should have some extra stuff in there but oh well

I personally hate mail(). It's slow, and not very customisable.

My own mail scripts are a lot faster, and can do a lot more, so I tend to stick to them :)

::] krycek [::

x_goose_x
04-15-2003, 09:24 PM
my mail server doesn't require authentication or the EHLO command.

krycek
04-15-2003, 10:33 PM
It should still have HELO

::] krycek [::

ConfusedOfLife
04-16-2003, 07:45 PM
x_goose_x: May I have the address of those tutorials?! I don't know how to send an email via smtp.

krycek: Are your functions open source?! May I take a look at them?!

krycek
04-16-2003, 08:28 PM
confused_of_life: yup, they are OpenSource :) you are welcome to take a look.

Email me at krycek @ soapi . com and we can take it from there :)

::] krycek [::



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum