You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP Bootstrap模态框联系表单提交失败:无邮件/数据发送

Troubleshooting Your Bootstrap Modal Contact Form Not Sending Emails

Hey there, let's dig into why your contact form is just refreshing the page instead of sending emails and processing your data. I’ve spotted a few key issues in your code that are almost certainly causing this:

1. Case Sensitivity Issue in Submission Check

This is the biggest culprit right now. Your PHP code checks for $_POST['Submit'] (capital S), but your submit button has name="submit" (lowercase s). PHP’s $_POST array is case-sensitive, so this condition never triggers—meaning your email-sending code never runs at all, and the page just refreshes like nothing happened.

Fix:
Update your PHP condition to match the button’s name exactly. Change this line:

if(isset($_POST['Submit'])){

To this:

if(isset($_POST['submit'])){

Or alternatively, rename your button’s name attribute to Submit—just make sure they match either way.

2. Broken Form Layout Markup

Looking at your HTML, the "Subject" input field’s container isn’t wrapped in a Bootstrap form-group div. While this might not directly stop form submission, it can cause rendering glitches and might lead to unexpected behavior in some browsers.

Fix:
Wrap the subject input’s column in a form-group:

<div class="form-group">
    <div class="col-xs-6 col-sm-4">
        <div class="form-material form-material-primary">
            <input class="form-control" type="text" id="contact-subject" name="contact-subject" placeholder="Enter your subject..">
            <label for="contact-subject">Subject</label>
        </div>
    </div>
</div>

3. Potential Email Delivery & Content Improvements

Even after fixing the above, you might run into issues with email delivery or content clarity:

  • Server Mail Configuration: Ensure your web server supports PHP’s mail() function. Many shared hosts enable it by default, but if you’re on a VPS or local server, you might need to configure an SMTP service (like using PHPMailer instead of the native mail() function for more reliability).
  • Department Value Clarity: Your dropdown uses numeric values (1 for Tech Support, 2 for Billing) but your email displays "To : '.$division.' Division". This will show "To : 1 Division" instead of the actual department name. Update your dropdown options to use the department name as the value:
    <select class="form-control" id="faq-contact-subject" name="faq-contact-subject" size="1">
        <option value="Tech Support">Tech Support</option>
        <option value="Billing">Billing</option>
    </select>
    
  • Debug Email Sending: Add error handling to the mail() function to see if it’s failing silently:
    if(mail($to, $subject, $message, $headers)){
        echo "Support message Sent. Thank you " . $first_name . ", we will contact you shortly.";
    } else {
        echo "Oops! There was an error sending your message. Please try again later.";
        // For debugging only (remove in production):
        // error_log('Mail failed: ' . print_r(error_get_last(), true));
    }
    

4. Test the Form After Fixes

Once you’ve applied the first two fixes, test submitting the form again. If you still don’t get emails, check your server’s error logs or use the debugging code above to see what’s going wrong with the mail() function.

内容的提问来源于stack exchange,提问作者anabelle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:00:33