mymotherland
mymotherland

Reputation: 8228

Mail is not coming properly using php?

I am using below simple code to send mail using php. when i echo the line $headers = "From: . $email\r\n"; //echo $headers; exit; which results like From: . [email protected]. I found dot is printing before mail address , so mail is coming but not properly.If i remove dot , mail is not even coming.Whats wrong with this code ?

<?php
if (isset($_REQUEST['user_email']))
//if "email" is filled out, send email
  { 
  //send email
  $email = $_REQUEST['user_email'];
  $user_name = $_REQUEST['user_name'];
  $user_message = $_REQUEST['user_message'];
  include 'contact_mail_form.php';
  $to = "[email protected]"; 
  $message = $contactText; 
  $subject = "Test Mail";
  $headers = "From: . $email\r\n"; //echo $headers; exit;
  $headers .= "Content-type: text/html\r\n";  
  mail($to,$subject,$message,$headers);
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {

?>
              <form id="contact_form" name="ContactForm" action="" method="post" onsubmit="return checkContact(this);">
                <div class="wrapper">
                  <div class="fright">
                    <div class="name">Message:</div>
                     <textarea cols="1" rows="1" name="user_message" id="user_message" ></textarea>
                    <span class="clear"></span> </div>
                  <div class="fleft">
                    <div>
                      <div class="name">Your Name:</div>
                       <input type="text" class="input" name="user_name" id="user_name"  />
                      <span class="clear"></span> </div>
                    <div>
                      <div class="name">E-mail:</div>
                        <input type="text" class="input"  name="user_email" id="user_email" />
                      <span class="clear"></span> </div>
                  </div>
                </div>
                <div class="buttons"><a class="more" href="javaScript:void(0);" onClick="document.getElementById('contact_form').reset()">clear</a> <input class="more1" type="SUBMIT" class="button2" value="Send" name="" /> </div>
              </form>
                <?php } ?>

Upvotes: 0

Views: 342

Answers (1)

Seder
Seder

Reputation: 2763

Try it like this your dot is acting as string not as concatenation

  $headers = "From:" . $email."\r\n"; 

Maybe because \r\n should be surrounded with " not '

And Also

$headers .= 'Content-type: text/html'. "\r\n"; 

Upvotes: 3

Related Questions