0

I'm currently trying to create a very basic PHP script which gets the content from a html form, stores them as variables and then sends an email containing said information.

After implementing this, all seems to be working apart from the actual message information.

My HTML reads:

<table style="width:100%"> 
    <form action="form_complete.php" method="POST"> 
    <tr> 
        <th> <input type="text" name="name" required placeholder="Name" /> </th> 
        <th> <input type="text" name="email" required placeholder="Email" /> </th> 
   </tr> 
   <tr> 
        <th> <input type="text" name="mobile" required placeholder="Mobile" /> </th> 
        <th> <input type="text" name="subject" required placeholder="Email Subject" /> </th> 
   </tr> 
   <tr> 
        <th colspan="2"> <textarea name="message" required placeholder="Enter your message"></textarea> </th> 
   <tr> 
        <th> </th> 
        <th> <input id="submit" type="submit" name="submit" value="Send" /> </th> 
   </tr> 

and the relevant PHP reads:

if(isset($_POST['submit'])){
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$mobile = $_POST['mobile']; 
$subject = $_POST['subject'];
$getMessage = $_POST['message']; 
$subject2 = "Receipt of email submission";
$message = "You have received a new email from " . $name . ". \n    Message: " . $getMessage; 
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);

Like I said, when I check the content of the email, the name parses fine, as does the mobile number and subject, but the content of the message doesn't seem to and I have no idea why.

2
  • 1
    Possible duplicate of How to send an email using PHP? Commented Mar 18, 2016 at 14:43
  • What do you mean by but the content of the message doesn't seem to? How is it formatted incorrectly? Commented Mar 20, 2016 at 9:59

1 Answer 1

1

Try to use PhpMailer for your emails. Also if you want use PHP mail function try this:

$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.