send email, how to solve this error?

  • nrsh_ram
  • Novice
  • Novice
  • nrsh_ram
  • Posts: 30
  • Loc: malaysia

Post 3+ Months Ago

i have create forgetpassword.php..when i try to run it...its show this 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\xampp\htdocs\nrsh\forgetpassword.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\nrsh\forgetpassword.php:24) in C:\Program Files\xampp\htdocs\nrsh\forgetpassword.php on line 25
Code: [ Select ]
<?php
$msg="";
if(isset($_POST['Submit']))
{
    if(empty($_POST['studentname']))
        {
        $msg="Mentee Name cannot be empty.";
        }
    elseif(empty($_POST['Loginid']))
        {
        $msg="Mentee Login id cannot be empty.";
        }
    elseif(empty($_POST['comments']))
        {
        $msg="comments cannot be empty.";
        }
    else
        {
        
            $to = "smiiledaa@gmail.com";
            $subject = 'MSU - Fogot Password';
            $message = "\n Mentee Name:".$_POST['studentname']."\n Mentee Login id :".$_POST['Loginid']."\n".$_POST['comments'];
            $headers = "From: MSI\r\n";
            mail($to, $subject, $message, $headers); 
            header("Location: mindex.php"); 
        }
        
        
}
                            
?>
  1. <?php
  2. $msg="";
  3. if(isset($_POST['Submit']))
  4. {
  5.     if(empty($_POST['studentname']))
  6.         {
  7.         $msg="Mentee Name cannot be empty.";
  8.         }
  9.     elseif(empty($_POST['Loginid']))
  10.         {
  11.         $msg="Mentee Login id cannot be empty.";
  12.         }
  13.     elseif(empty($_POST['comments']))
  14.         {
  15.         $msg="comments cannot be empty.";
  16.         }
  17.     else
  18.         {
  19.         
  20.             $to = "smiiledaa@gmail.com";
  21.             $subject = 'MSU - Fogot Password';
  22.             $message = "\n Mentee Name:".$_POST['studentname']."\n Mentee Login id :".$_POST['Loginid']."\n".$_POST['comments'];
  23.             $headers = "From: MSI\r\n";
  24.             mail($to, $subject, $message, $headers); 
  25.             header("Location: mindex.php"); 
  26.         }
  27.         
  28.         
  29. }
  30.                             
  31. ?>


how to fix this error?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

For the headers sent error, you could try putting ob_start(); before the header("locatuib: mindex.php") and then put ob_end_flush(); right after.

If that doesn't work, than you could use JavaScript to redirect... just echo the JavaScript in the PHP script.

As for the mail error, the mail uses SMTP to send message... the host, port and the password are all editable in the PHP.ini
  • zealus.com
  • Beginner
  • Beginner
  • User avatar
  • Posts: 36
  • Loc: NY

Post 3+ Months Ago

As long as you fix the first error you shouldn't worry about the second. The reason for it is that the page headers were indeed already sent by an error message, so once you get rid of that (most likely - by specifying a correct SMTP host/credentials) you'll take care of a second.

Good luck!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 74 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.