Mail() in IIS5/SMTP

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
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Mail() in IIS5/SMTP

Post by Flash05 »

Question regarding PHP/iiS5/SMTP. I'm testing my script for my mail form:

<?php
$mail_to = "testing@yahoo.com";
$mail_subject = "Testing";
$mail_body = "Test body...";
$mail_from = "Testing@PHP.com";
if(mail($mail_to, $mail_subject, $mail_body, $mail_from))
echo "Successfully sent the e-mail \"$mail_subject\" to $mail_to.";
else echo "Failed to send the e-mail \"$mail_subject\" " . "to \"$mail_to\""
?>

Yesterday, I was able to send mail. Unfortunately, when I tested my script later, it was no longer sending mail. Is there a configuration or some sort to be able for me send email? I already change my php.ini SMTP to "SMTP = localhost", to use my local smtp. My connection outside was dialup. Im using Windows XP Pro and iiS5.01. Can someone help me with this. Thanks!
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

Btw, is there special configuration or setting for iiS or smtp to be able to send again emails?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You need to put From: before the email address... $mail_from = "From:Testing@PHP.com";
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

Tnx for the reply.

<?php
$mail_to = "testing@yahoo.com";
$mail_subject = "Testing";
$mail_body = "Test body...";
$mail_from = "From:Testing@PHP.com";
if(mail($mail_to, $mail_subject, $mail_body, $mail_from))
echo "Successfully sent the e-mail \"$mail_subject\" to $mail_to.";
else echo "Failed to send the e-mail \"$mail_subject\" " . "to \"$mail_to\""
?>

I've changed the script according to your suggeston. It still not sending, though yesterday it was fine and was able so send email using localhost smtp. Is ther any other solution. Please help me. TNx!
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Shouldn't there be brackets with the if statement? I also see a colon missing from the second to last line..
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Hmmm.. see if this works..

Code: Select all

<?php

$mail_to = "testing@yahoo.com"; // Is this a real email address? I think it might need to be
$mail_subject = "A test email";
$mail_body = "Oooh curvey body";
$mail_from = "From:someone@somewhere.com";

$email_result = mail($mail_to, $mail_subject, $mail_body, $mail_from);

if($email_result)
{
    echo "Email has been sent.";
}
else
{
    echo "DOH!";
}

?>
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

TNx for reply. Your suggested code works, the result is "DOH!" It wasn't able to send the mail.

Actaully i got the code from a book and modified it. It works fine yesterday morning. When I tried it later, it no longer worked. I'm not sure what's the problem but I think it's not the code (maybe...). Maybe there is a setting in IIS?

By the way, I tried it yesterday using dialup connection (I have outside IP). Can this work even though i have a non-routable IP?

Tnx again...
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

What maybe the reason behind this? I'm not sure if I made some changes yesterday to my iiS? Can someone here help me setup my iiS/smtp serveR? tnx! Thankyou also for the help in the script... :D
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Just out of interest, are you trying to run the code on-line or off-line?

I have Apache/PHP etc installed on my home computer and I made the mistake once of trying to send emails from my computer (http://127.0.0.1) without being connected to the web... with obviously didn't work.
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

On-line. Im using XP/iis5.01. I was able to send mail and was happy about it. Turned off my pc, then when I got back to try again my script for sending email, it won't send... Strange... btw, here's d script:

<?php
$mail_to = "testing@yahoo.com";
$mail_subject = "Testing";
$mail_body = "Test body...";
$mail_from = "From:Testing@PHP.com";
if(mail($mail_to, $mail_subject, $mail_body, $mail_from))
echo "Successfully sent the e-mail \"$mail_subject\" to $mail_to.";
else echo "Failed to send the e-mail \"$mail_subject\" " . "to \"$mail_to\""
?>

php.ini
SMTP = localhost
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Configuring my IIS/SMTP for mail()

Post by Flash05 »

Newbie here... Can somebody walk me through the process of configuring my IIS's SMTP so that I can test my mail form. Im using Windows XP Pro, IIS 5.01, PHP... Thanks in advance... :D
Post Reply