Page 1 of 1

Can't get mail function to work on Windows / IIS

Posted: Sat May 22, 2004 4:06 pm
by Zooter
I'm trying to send an email to a user who has just logged in. I've tried the mail() function, and set the values in my php.ini file to my ISP's smtp server, but it just doesn't want to work. I've even tried the PEAR Mail function where you can tell it to use PHP's mail, SMTP or whatever, but also doesn't work.

All that happens is that the mail() function returns FALSE everytime.

Please can someone advise me on this.?

Windows XP, IIS 5.1, PHP 4.3.6.

Posted: Sat May 22, 2004 4:52 pm
by launchcode
The mail function will return false if the format of the email is invalid - it doesn't return false just because it cannot send the email, all it does is deliver it to the SMTP server, it's up to the server to send it.

What code are you using to format your email (before passing to mail(), etc) ?

Posted: Sat May 22, 2004 4:58 pm
by Zooter
// Let's mail the user!
$subject = "Your Membership at MyWebsite!";
$message = "Dear $first_name $last_name,
Thank you for registering at our website, http://www.mydomain.com!

You are two steps away from logging in and accessing our exclusive members area.

To activate your membership,
please click here: http://www.mydomain.com/activate.php?id ... b_password

Once you activate your memebership, you will be able to login
with the following information:
Username: $username
Password: $random_password

Thanks!
The Webmaster

This is an automated response, please do not reply!";

if (@mail($email_address, $subject, $message . phpversion())){
echo ("Your membership information has been mailed to your email address! Please check it and follow the directions!");
} else {
echo ("Not working!");
}

I use this code, but all is get back is the text in the else part... Not working!....

Posted: Sat May 22, 2004 5:06 pm
by launchcode
You've got no from / reply-to address, most SMTP servers I've ever used will freak out at this and reject the mail.

Try something far more simple just to see if it works:

Code: Select all

mail('someone@domain.com', 'Subject', 'Hello', 'From: your@real_email.com');

Posted: Sat May 22, 2004 5:11 pm
by Zooter
Still does the same thing. my php.ini settings are like this...

[mail function]
; For Win32 only.
SMTP = smtp.mighty.co.za

; For Win32 only.
sendmail_from = zooter@mighty.co.za

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

Posted: Sat May 22, 2004 5:13 pm
by Zooter
Now it's working... Restarted IIS... After I used that simpler code.. Will quickly retest with a from address in the old code, and let you know.

Posted: Sat May 22, 2004 5:15 pm
by Zooter
Great stuff!! Does it make a difference whether the from address is 'From: realemail@bla' or just 'realemail@bla'?

Posted: Sat May 22, 2004 7:22 pm
by launchcode
That parameter is an email header, in other words the From: part is *essential*.

Posted: Sun May 23, 2004 4:44 am
by Zooter
Thanks alot for your help.