普通网友 2013-07-10 05:36
浏览 48

简单联系表格的问题

I apologize in advance for any rookie mistakes, as this is my first real attempt at piecing together a HTML / PhP contact form. I've scoured previous questions with identical issues and haven't found anything of substance.

The issue is the email is not sending. Things I've tried thus far: - Confirmed SMTP functions - Confirmed it's not a host-related issue - Used this exact form / PHP mailer on another template and it works fine - Checked spam folder

Here is the contact form itself:

    <form action="contact.php" method="POST" id="contact-form" class="form">
    <input type="hidden" value="" name="check">
    <noscript>
    <p class="noscript">JavaScript is required to use this form, please make sure your browser supports it.</p>
    </noscript>
    <p class="input">
    <label for="name" class="label">Name</label>
    <input type="text" name="name" id="name">
    </p>
    <p class="input">
    <label for="company" class="label">Company</label>
    <input type="text" name="company" id="company">
    </p>
    <p class="input">
    <label for="email" class="label">Email</label>
    <input type="text" name="email" id="email">
    </p>
    <p class="input">
    <label for="phone" class="label">Phone</label>
    <input type="text" name="phone" id="phone">
    </p>
    <p class="dark input">
    <label for="title" class="label">Project Title</label>
    <input type="text" name="title" id="title">
    </p>
    <p class="dark input">
    <label for="timeline" class="label">Timeline</label>
    <input type="text" name="timeline" id="timeline">
    </p>
    <p class="dark textarea">
    <label for="details" class="label">Details</label>
    <textarea name="details" id="details"></textarea>
    </p>
    <p>
    <label for="send" class="send-label">Everything look good? Click send.</label>
    <input type="submit" value="Submit" name="submit" class="button">
    </p>
    </form>

Here is the PHP mailer:

    <?php
    $field_name = $_POST['name'];
    $field_company = $_POST['company'];
    $field_email = $_POST['email'];
    $field_phone = $_POST['phone'];
    $field_title = $_POST['title'];
    $field_timeline = $_POST['timeline'];
    $field_message = $_POST['details'];

    $mail_to = 'MyEmail@email.com';
    $subject = 'Quote request from '.$field_name;

    $body_message = 'From: '.$field_name."
";
    $body_message .= 'E-mail: '.$field_email."
";
    $body_message .= 'Message: '.$field_message;

    $headers = 'From: '.$field_email."
";
    $headers .= 'Reply-To: '.$field_email."
";

    $mail_status = mail($mail_to, $subject, $body_message, $headers);

    if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you for the message. We will contact you shortly.');
    window.location = 'contact.html';
    </script>
    <?php
    }
    else { ?>
    <script language="javascript" type="text/javascript">
    alert('Message failed. Please contact the webmaster.');
    window.location = 'contact.html';
    </script>
    <?php
    }
    ?>

Just for reference, the "MyEmail@email.com" is not the email I use. I used a substitute for privacy purposes.

Thank you!

  • 写回答

2条回答 默认 最新

  • dongpi9164 2013-07-10 05:40
    关注

    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;
    • Outbound mail on port 25 is blocked, and you have to use a specific server.
    • 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.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP