sending mail, not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

sending mail, not working

Post by m3mn0n »

This worked before for me, but since i upgraded my version of php it doesn't at all. :?
sendmail.php wrote: Warning: Failed to Connect in c:\...\...\...\sendmail.php on line 25

Code: Select all

<?php
// set up a message
$subject = "hello!";
$msg = "hi
\n
how's it going?";
$headers = "From: "Oromian" <oromian@hotmail.com>";

// connect to the database and collect addresses
require ("dbinfo.php");
$sql = "select email from emails";
$res = @mysql_query($sql) or die("Couldn't get addresses.");

// loop through the result set and send mail
while ($email_row = @mysql_fetch_array($res)) {

  // get the recipient address
  $to = $email_row['email'];

  //send the mail
  mail("$to", "$subject", "$msg", "$headers");

  //print a confirmation to the screen
  echo "mail sent to $to <br>";
}
?>
Line 25 is the mail() line, it can't be the code that's wrong i had the exact same version of code working on my previous php install. My current version is 4.1.1, my OS is Windows XP Pro. Did i miss a patch or some sort of setting adjustment news headline?

Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what does

Code: Select all

<?php
echo 'connecting ', ini_get('SMTP'), ':', ini_get('smtp_port');
flush();
$f = fsockopen(ini_get('SMTP'),  ini_get('smtp_port')) or die(' failed');
echo ' done';
?>
do?
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Also, what is the smtp server setting in your php.ini.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
sendmail_from = oromian@hotmail.com

Volka:
connecting localhost: done

And i just confirmed it's not my firewall either. It must be something else...
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

anyone?

:(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm hm hm
what kind of smtp server is listening on localhost:25 ?
does it require some kind of authentication?

The only location in the php-win32-code I see that outputs such an error is sendmail.c in int TSendMail(...) when int MailConnect() returns something else than 0. And this happens here....

Code: Select all

if ((sc = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
		return (FAILED_TO_OBTAIN_SOCKET_HANDLE);

	/* Get our own host name */
	if (gethostname(LocalHost, HOST_NAME_LEN))
		return (FAILED_TO_GET_HOSTNAME);
...
	/* Resolve the servers IP */
	/*
	if (!isdigit(MailHost&#1111;0])||!gethostbyname(MailHost))
	&#123;
		return (FAILED_TO_RESOLVE_HOST);
	&#125;
...
	if (connect(sc, (LPSOCKADDR) & sock_in, sizeof(sock_in)))
		return (FAILED_TO_CONNECT);
very strange that you can create a socket with php but it cannot create/connect the socket internally...
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

ugh

i guess i'm stuck with a not fully functional server again.. :evil:
Post Reply