Jump to content

e-mail script don't work


mariocesar

Recommended Posts

Hello this sis the message I receive :

Warning: mail(): Bad parameters to mail() function, mail not sent. in /home/content/C/o/p/Copymail/html/password.php on line 36

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/C/o/p/Copymail/html/password.php:36) in /home/content/C/o/p/Copymail/html/password.php on line 41

 

this is the code:

 

<?
include("fns.php");
include "config.php";
if(isset($_POST['Submit'])){
//1. Check if form fields are filled in
if(!filledin($_POST)){
header( "Location:Messages.php?msg=7" ); 
exit();
}
$name=$_POST['name'];
$em=$_POST['mail'];

//2. Check if entered name exist

$query="Select pw from user where uname='$name'" or die(mysql_error());
$result= mysql_query($query); 

if(mysql_num_rows($result)>0){
for ($i=0; $i<mysql_num_rows($result); $i++) {
$row = mysql_fetch_assoc($result);

$pass=$row['pw'];
$to="$em\r\n";
$from="From: [email protected]\r\n";
$msg="Password:$pass\r\n";
$msg .="Username:$name\r\n";
$msg .="Please change your password as soon as you logon\r\n";
$subject="From Admin re:Your Login Password\r\n";
}
}else{
header( "Location:Messages.php?msg=8" ); 
exit();
}

//4. Send password to user
if(mail($to,$subject,$msg,$from)){
header( "Location:Messages.php?msg=9&email=<?php echo $em; ?>" ); 
exit();
//echo "Please click here to log";
}else{
header( "Location:Messages.php?msg=10"); 
exit();
}
}

?>

 

this is lne 36 :

if(mail($to,$subject,$msg,$from)){

 

this is 41:

header( "Location:Messages.php?msg=10");

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/36546-e-mail-script-dont-work/
Share on other sites

Try this... You don't need all the \r\n on the end of every parameter passed to mail(), only the additional headers.

 

<?php
include("fns.php");
include "config.php";

if(isset($_POST['Submit'])){
   //1. Check if form fields are filled in
   if(!filledin($_POST)){
      header( "Location:Messages.php?msg=7" ); 
      exit();
   }
   $name=$_POST['name'];
   $em=$_POST['mail'];

   //2. Check if entered name exist

   $query="Select pw from user where uname='$name'" or die(mysql_error());
   $result= mysql_query($query);

   if(mysql_num_rows($result)>0){
      for ($i=0; $i<mysql_num_rows($result); $i++) {
         $row = mysql_fetch_assoc($result);
         $pass = $row['pw'];

         $to = $em;
         $from = "From: [email protected]\r\n";
         $msg = "Password: $pass";
         $msg .= "Username: $name";
         $msg .= "Please change your password as soon as you logon";
         $subject = "From Admin re: Your Login Password";
      }
   }else{
      header( "Location:Messages.php?msg=8" ); 
      exit();
   }

   //4. Send password to user
   if(mail($to,$subject,$msg,$from)){
      header( "Location: Messages.php?msg=9&email=$em" ); 
      exit();
      //echo "Please click here to log";
   }
   else{
      header( "Location:Messages.php?msg=10"); 
      exit();
   }
}
?>

 

Regards

Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.