Search code examples
phphtmlemailmailto

Can't send PHP mail! Form mail


    <form action="" enctype="text/plain" method="post">
    <textarea name="link" style="margin-left: 0px; margin-right: 0px; width: 591px;" cols="1" rows="1" placeholder="Link"></textarea>

    <textarea name="username" style="margin-left: 0px; margin-right: 0px; width: 591px;" cols="1" rows="1" placeholder="Username"></textarea>

    <input type="submit" value="send" /></form>
<div style="color: red;">*Warning</div>
- Do not submit the request more than once if you do not want duplicate items.

<?php
$to      = 'admin@bdeas.com';
$subject = 'Market Purchase';
$message = htmlspecialchars($_POST['username']);
$message2 = htmlspecialchars($_POST['name'])
$headers = 'From: admin@bdeas.com' . "\r\n" .
    'Reply-To: admin@bdeas.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $message2, $headers);
?> 

I have this code here but I can't seem to get this code to send the mail. I have looked at the other posts but they don't help me as I need the form details to send the mail.

EDIT! Could you tell me if there is anything wrong in the code?


Solution

  • You can't have 2 messages like that. You need to join all parts of your final message into a string. If you want to include them both, do this:

    <?php
        $to      = 'admin@bdeas.com';
        $subject = 'Market Purchase';
        $message = $_POST['username'] . '<br />' . $_POST['name'];
        $headers = 'From: admin@bdeas.com' . "\r\n" .
            'Reply-To: admin@bdeas.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
    
        mail($to, $subject, $message, $headers);
    ?>