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

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
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

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

Post 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.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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) ?
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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!....
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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');
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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 =
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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.
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

Great stuff!! Does it make a difference whether the from address is 'From: realemail@bla' or just 'realemail@bla'?
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

That parameter is an email header, in other words the From: part is *essential*.
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

Thanks alot for your help.
Post Reply