Page 1 of 1

mail() function not working! Please provide input.

Posted: Sun May 03, 2009 5:46 am
by ice52us
I have Windows XP.
I have Apache 2.2.11
I have PHP 5.2.9

In my code i am using the function mail() in the following manner:

Code: Select all

 
<?php
$to = 'ice52us@yahoo.com';
$subject = 'Abduction Report';
$msg = 'Test Mesage';
$email = 'Someone@yahoo.com';
mail($to, $subject, $msg, 'From:' . $email);
?>
 
There are no errors and no results. WHY??!?!??!?!?!
I don't know what I'm doing wrong.

After looking on forums for a while, I found and tried this piece of code:

Code: Select all

 
if (mail($to, $subject, $msg)) {
echo 'Mail Sent';
} else {
echo 'Mail NOT Sent';
}
 
I'm not sure what it means, but the page countinuously says: Mail NOT Sent.
Please tell me how to correct my mistakes.

Re: mail() function not working! Please provide input.

Posted: Sun May 03, 2009 8:47 am
by Bill H
The mail function requires a mail server. Are you running an smtp server on your system?

Re: mail() function not working! Please provide input.

Posted: Sun May 03, 2009 1:39 pm
by ldougherty
In your php.ini look for these lines..

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

You will need to define your mail server here as PHPs mail() function requires this information.

After changing this data to the appropriate information such as your ISP or Web Host's SMTP server just save the php.ini and restart Apache.

Re: mail() function not working! Please provide input.

Posted: Sun May 03, 2009 1:50 pm
by ice52us
How do I check if I have a mail server?
How do I check what kind of mail server I have and what to put in the .ini file?
How do I install a mail server?
Which one would be most compatible with my PHP, Local Web Server, and Operating System?

p.s. thank you for your responseses.

Re: mail() function not working! Please provide input.

Posted: Sun May 03, 2009 2:14 pm
by ldougherty
What it is exactly that you are attempting to accomplish? Are you trying to run a web server from your home machine or is this a hosted server?

Re: mail() function not working! Please provide input.

Posted: Sun May 03, 2009 4:54 pm
by ice52us
I'm running a server from my home computer to test php code I write before uploading it online.
The mail() function is not working, meaning I'm not getting any emails when the form is submitted.
I tried it online, and instead of saying Mail NOT Sent, it says mail sent, so obviously that has something to do with the mail server not being on my computer, but I'm still not getting any mail!!!
This is so frustrating! What do I need to do to recieve mail?? Please help!
This is the script for reference:

Code: Select all

<?php
 
    $subject = 'Abduction Report';
    $to = 'ice52us@gmail.com';
    $name = $_POST['firstname'] . ' ' . $_POST['lastname'];
    $howMany = $_POST['howmany'];
    $when = $_POST['whenithappened'];
    $howLong = $_POST['howlong'];
    $description = $_POST['description'];
    $beer = $_POST['beer'];
    $fang = $_POST['fangspotted'];
    $email = $_POST['email'];
    $whatTheyDid = $_POST['whattheydid'];
    $other = $_POST['other'];
    $msg = "$name was abducted $when and was gone for $howLong.\n" .
        "The aliens were $description and were all drinking $beer.\n" .
        "There were $howMany and they $whatTheyDid.\n" .
        "Was Fang there? $fang.\n" .
        "Other Comments: $other";
    mail($to, $subject, $msg, 'From:' . $email);
    
 
    
    
    echo 'Thank you for submitting the form, ' . $name . '<br>';
    echo 'You were abducted ' . $when;
    echo ' and were gone for ' . $howLong . '<br>';
    echo 'Describe them: ' . $description;
    echo ' and they were all drinking ' . $beer . '<br>';
    echo 'There was ' . $howMany . ' and they ' . $whatTheyDid . '<br>';
    echo 'Was Fang there? ' . $fang . '<br>';
    echo 'Your email address is: ' . $email;
    echo '<br>';
    if (mail($to, $subject, $msg)) {
echo 'Mail Sent to ' . $to;
} else {
echo 'Mail NOT Sent';
}
 
 
?>

Re: mail() function not working! Please provide input.

Posted: Sun May 03, 2009 5:57 pm
by ice52us
Ok I downloaded "Free SMTP Server" program. When I run it, it says
Waiting for connection on port #25; Using DNS Server 88.828.838.334
When I try to submit the form once more from localhost://report.php, it still says Mail NOT Sent. When I upload the file to online web hosting, it says Mail Sent, but I never recieve any mail.
I'm really stuck, please help.

Re: mail() function not working! Please provide input.

Posted: Mon May 04, 2009 7:42 am
by ldougherty
As I stated previously you will need to configure the SMTP mail server in your php.ini locally. You can either..

- Install your own mail server which is a bit much for testing purposes only.

- Use your ISPs SMTP server (Comcast, etc)

- Use your web hosts SMTP server

You should be able to get this information from your ISP or Web Host, it is the same information as your outbound email server when sending mail through their servers.