doubiaokai4998 2013-07-09 14:43
浏览 13
已采纳

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!

  • 写回答

1条回答 默认 最新

  • duanqi5114 2013-07-09 14:55
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错