Sending mail from website

Discussion in 'PHP' started by rrn, Apr 2, 2009.

  1. #1
    hi.....

    my website is in php , sql ,html....i have written a code for sending mails from the site... mails are coming to my id... but the problem is tat... wen i send one mail... more than 30 mails are coming to my inbox...
    $email_from = $_POST['name']." ".$_POST['email']; // Who the email is from
    $email_subject = 'Email Alerts from Website';
    $email_message =          '
    	               <table cellpadding="3" cellspacing="1" border="0" width="600">
                                                                                           <tr>
    				                   <td>'.$_POST[name].' has sent the details from Email Alerts</td>
    				</tr>
    
    				<tr>
    					<td width="120">Name</td>
    					<td>'.$_POST[name].'</td>
    				</tr>
    
    				<tr>
    					<td width="120">Email</td>
    					<td>'.$_POST[email].'</td>
    				</tr>
                     </table>
    				';
    
    $email_to  = 'test@test.com';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= "From: ".$_POST[email];
    @mail($email_to, $email_subject, $email_message,  $headers);
    
    PHP:
    this is the code?? i cant find out problem..pls help me out...

    thank u...
     
    rrn, Apr 2, 2009 IP
  2. Stylesofts

    Stylesofts Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello,

    THere is nothing wrong wid the codes..but..
    /// whose email address is this//
    is this vaild email address

    this is the address where email is send. so it would be better if you put your email address and also use the following codes and put ur email address replacing the text

    
    <?php
    $email_from = $_POST['email']; 
    // Who the email is from
    $email_subject = 'Email Alerts from Website';
    $email_message = ' <table cellpadding="3" cellspacing="1" border="0" width="300"> <tr>                                  
    <td colspan="2">'.$_POST[name].' has sent the details from Email Alerts</td> 
    </tr> 
    <tr> 
    <td width="120">Name</td>
    <td width="180">'.$_POST[name].'</td>
    </tr> 
    <tr> 
    <td width="120">Email</td> 
    <td width="180">'.$_POST[email].'</td>  
    </tr> 
    </table>                ';
    #$email_to  = 'test@test.com';
    $email_to = "Replace this wid Your email address or the email address where the message comes"
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= "From: $email_from";
    @mail($email_to, $email_subject,$email_message$headers);
    ?>
    
    PHP:
    Hope the problem is solved

    Regards
    Stylesofts Developing Team.
     
    Stylesofts, Apr 2, 2009 IP
  3. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Correction to previously posted:
    
    <?php
    $email_from = $_POST['email'];
    // Who the email is from
    $email_subject = 'Email Alerts from Website';
    $email_message = ' <table cellpadding="3" cellspacing="1" border="0" width="300"> <tr>                                 
    <td colspan="2">'.$_POST[name].' has sent the details from Email Alerts</td>
    </tr>
    <tr>
    <td width="120">Name</td>
    <td width="180">'.$_POST[name].'</td>
    </tr>
    <tr>
    <td width="120">Email</td>
    <td width="180">'.$_POST[email].'</td> 
    </tr>
    </table>                ';
    #$email_to  = 'test@test.com';
    $email_to = "Your email address or the email address where the message comes"
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= "From: $email_from";
    @mail($email_to, $email_subject,$email_message,$headers);//missed the last ,
    ?>
    
    PHP:
     
    NatalicWolf, Apr 2, 2009 IP
  4. rosseric

    rosseric Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You shouldn't be passing user input directly to mail(), that can be abused. you can see example of such bug here htxp://secunia.com/advisories/7776/ (replace to http, it won't let me post links)

    just use str_replace(array("\r","\n"), '', $_POST['foo']) instead of $_POST['foo'] directly. it'll remove newlines and make it secure.
     
    rosseric, Apr 2, 2009 IP
  5. rrn

    rrn Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank u for all the replies...

    rosseric , can u pls explain where should i use this str_replace(array("\r","\n"), '', $_POST['foo']) ?? can u pls show me??

    thank u..
     
    rrn, Apr 4, 2009 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Here is an example of what he means:
    This should work without trouble.

    
    <?php
    $email_from = str_replace(array("\r","\n"),'',$_POST['email']);
    // Who the email is from
    $email_subject = 'Email Alerts from Website';
    $email_message = ' <table cellpadding="3" cellspacing="1" border="0" width="300"> <tr>                                 
    <td colspan="2">'.str_replace(array("\r","\n"),'',$_POST[name]).' has sent the details from Email Alerts</td>
    </tr>
    <tr>
    <td width="120">Name</td>
    <td width="180">'.str_replace(array("\r","\n"),'',$_POST[name]).'</td>
    </tr>
    <tr>
    <td width="120">Email</td>
    <td width="180">'.str_replace(array("\r\n"),'<br>',$_POST[email]).'</td>
    </tr>
    </table>                ';
    #$email_to  = 'test@test.com';
    $email_to = "Your email address or the email address where the message comes"
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= "From: $email_from";
    @mail($email_to, $email_subject,$email_message,$headers);//missed the last ,
    ?>
    
    PHP:
     
    NatalicWolf, Apr 5, 2009 IP