PHP电子邮件不起作用[关闭]

I'm trying to figure out how to build a contact form, but I can't understand where is the error. This is my html form:

<form id="contact-form" method="post" action="mail.php"> <!-- contact form -->
   <h4>Inviaci un Messaggio</h4>
   <div class="row-fluid">
    <div class="span4">
     <input type="text" name="name" maxlength="80" placeholder="Nome (richiesto)" />
    </div>
    <div class="span4">
     <input type="text" name="email" maxlength="255" placeholder="Email (richiesto)" />
    </div>
    <div class="span4">
     <input type="text" name="subject" placeholder="Oggetto" />
    </div>
   </div>
   <textarea name="message" placeholder="Testo (richiesto)"></textarea>
   <input type="submit" name="submit" value="Invia" class="btn" />
  </form>

and this is mail.php

<?php
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
mail("my@mail.com", $subject,
$message, "From:" . $email);
?>

where am I wrong? Thanks!

Sending mail from PHP is fraught with difficulties. You might not have an error in your code, but the mail might not be delivered because (select as many as you wish):

  • it doesn't appear to come from an email address on the server;
  • outbound email is blocked by default until you ask for it;
  • your server is blacklisted;
  • your message is blocked by a spam filter;
  • some other reason.

Make life easy on yourself. Use a library like swiftmailer or PHPmailer to handle sending the mail, and try something easy like delivering to an address on the sending server. Then work up from there. Be prepared to have to use SMTP Authentication, and possibly a paid external service to send the mail for you.