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!
我正在试图弄清楚如何构建联系表单,但我无法理解错误在哪里 。 这是我的html表单: p>
&lt; form id =“contact-form”method =“post”action =“mail.php”&gt; &lt;! - 联系表格 - &gt;
&lt; h4&gt; Inviaci un Messaggio&lt; / h4&gt;
&lt; div class =“row-fluid”&gt;
&lt; div class =“span4”&gt;
&lt; input type =“text”name =“name”maxlength =“80”placeholder =“Nome(richiesto)”/&gt;
&lt; / div&gt;
&lt; div class =“span4”&gt;
&lt; input type =“text”name =“email”maxlength =“255”placeholder =“Email(richiesto)”/&gt;
&lt; / div&gt;
&lt; div class =“span4”&gt;
&lt; input type =“text”name =“subject”placeholder =“Oggetto”/&gt;
&lt; / div&gt;
&lt; / div&gt;
&lt; textarea name =“message”placeholder =“ Testo(richiesto)“&gt;&lt; / textarea&gt;
&lt; input type =”submit“name =”submit“value =”Invia“class =”btn“/&gt;
&lt; / form&gt;
pre>
这是mail.php p>
&lt;?php
$ email = $ _ POST ['email'] ;
$ subject = $ _POST ['subject'];
$ message = $ _POST ['message'];
mail(“my@mail.com”,$ subject,
$ message,“From:” 。$ email);
?&gt;
code> pre>
我哪里错了? 谢谢! p>
div>
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.