0

I wanted to add a php form that sends a message with a name and email of the one who sent it, this is my current html, btw i use bootstrap:

    <div class="row" id="contact-padding">
        <div class="col-md-12 text-center" id="contact-form1">
            <form action="mail.php" method="POST">
                <p></p><br><input type="text" name="name" placeholder="Име" id="formInput">
                <p></p><br><input type="text" name="email" placeholder="Поща"  id="formInput">
                <p></p><br><input type="text" name="phone" placeholder="Телефон" id="formInput">

                <p></p><br>
                    <textarea name="message" rows="6" cols="25" placeholder="Запишете съобщението, което искате да изпратите." ></textarea><br/><br>
                    <input type="submit" value="Изпрати" id="send">
                    <input type="reset" value="Изчисти" id="send">
            </form>
        </div>
    </div>
</div>

This is the PHP script that i use for this html:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Message: $message";
$recipient = "zombaza@abv.bg";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

Everytime i try to send the message, it just opens the php file on a new page and i dont receive the email on "zombaza@abv.bg"

I've tried a couple of things but they dont seem to work and it is really important that i finish this job so if somebody has an idea, please share it with me, i would be really thankful!

2 Answers2

0

Sending mail is notoriously open to SPAM. In your case, you're allowing unvalidated content to go directly into an email header: that's asking for trouble. You also need to be careful with white space and newlines.

To help project yourself, go for a trusted mail script/class/library. I regularly use swiftmailer (http://swiftmailer.org/) as it has suitable configuration, error trapping and so on.

If you need to fix your own code above, add in standard debugging (Check error_reporting and ini_set('display_errors') ) as they will reveal issues in the code. Put an "echo" at the top so you know you're calling the right script etc (the "open in a new page" actually suggests you have some JavaScript that's interfering - disable JS functions if that's the case).

But always check your inputs before outputting into email, databases or HTML pages.

Robbie
  • 17,605
  • 4
  • 35
  • 72
-1

add @ in this

  @mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
Katyoshah
  • 129
  • 10