MAIL FUNCTION

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
trim9001
Forum Newbie
Posts: 1
Joined: Tue Mar 14, 2006 2:29 pm

MAIL FUNCTION

Post by trim9001 »

Pls Help! I was trying to create a application with the "mail()" function. The prgram gives an error on the mail() function. I have php v5 and according to the php.net webpage, the function should work but it dosen't. PLS HELP!

HERE IS THE CODE:
<form action="mail.php" method="post">
<input type="text" name="text">
<br />
<br />
<label>
<textarea name="textarea"></textarea>
<br />
</label>
<br />
<input type="submit" name="submit" value="Submit">
</form><br />

Code: Select all

$to = "trim9001@yahoo.com";
$subject = "Results from your Request Info form"; 
$headers = "From: My Site"; 
$forward = 0; 
$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; 
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    foreach ($_POST as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}
else {
    foreach ($_GET as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}
mail($to, $subject, $msg, $headers); 
if ($forward == 1) { 
    header ("Location:$location"); 
} 
else { 
    echo "Thank you for submitting our form. We will get back to you as soon as possible."; 
}
ERROR:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files\Apache Group\Apache2\htdocs\mail.php on line 39
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

do you have a mail server set up on your server?

I'd bet no given the error.

try modifying your php.ini file to point to a valid SMTP server....
gchrome
Forum Newbie
Posts: 3
Joined: Thu Mar 16, 2006 2:27 pm

Post by gchrome »

Burrito is right, this is a common problem.

If you don't have access to the php.ini to make the change to the default SMTP server or if you need to have more detailed configuration options (ex. sending in both html and plain text) you should use the PHPMailer class available at http://phpmailer.sourceforge.net/

I have used it in many applications over the years and it is very handy for getting around the limitations of the regular php mail() function.
Post Reply