mail() function not working! Please provide input.

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
ice52us
Forum Newbie
Posts: 4
Joined: Sun May 03, 2009 5:25 am

mail() function not working! Please provide input.

Post 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.
Last edited by Benjamin on Sun May 03, 2009 6:09 am, edited 1 time in total.
Reason: Changed quote tags to code tags.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post by Bill H »

The mail function requires a mail server. Are you running an smtp server on your system?
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

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

Post 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.
ice52us
Forum Newbie
Posts: 4
Joined: Sun May 03, 2009 5:25 am

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

Post 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.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

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

Post 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?
ice52us
Forum Newbie
Posts: 4
Joined: Sun May 03, 2009 5:25 am

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

Post 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';
}
 
 
?>
Last edited by Benjamin on Sun May 03, 2009 5:22 pm, edited 1 time in total.
Reason: Changed quote tags to code=php tags.
ice52us
Forum Newbie
Posts: 4
Joined: Sun May 03, 2009 5:25 am

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

Post 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.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

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

Post 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.
Post Reply