doujiang1913 2014-11-07 03:53
浏览 28
已采纳

Bootstrap PHP表单不会发送任何东西

I'm trying to finish a project to help out a friend with his website and I can't get the contact form to work. When I hit send: it seems like it has sent but then nothing ends up in the inbox of the email address. (I can't even get Stackoverflow to work... keep getting a "your post appears to contain code that is not properly formatted as code")

Bellow is the website: pservices.comuf.com

Bellow is the PHP code:

<?php
// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['phone'])       ||
   empty($_POST['email'])       ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];

// create email body and send it    
$to = 'cgramsinjapan@hotmail.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "P Services Contact Form:  $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.

"."Here are the details:

Name: $name

Phone: $phone

Email: $email_address

Message:
$message";
$headers = "From: noreply@your-domain.com
";
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>
  • 写回答

1条回答 默认 最新

  • dtny30176 2014-11-07 03:58
    关注

    Far as I can see after going to the contact section of the site you posted, none of your form elements contain a name attribute.

    For instance:

    <input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
    

    would need to be changed to

    <input type="text" name="name" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
                       ^^^^^^^^^^^
    

    while adding the appropriate name attributes to the other form inputs.

    You cannot rely on the id attribute alone.

    Also this

    <form name="sentMessage" id="contactForm" novalidate>
    

    is missing a post method and an action:

    change it to

    <form method="post" action="handler.php" name="sentMessage" id="contactForm" novalidate>
    

    using handler.php as the PHP mail handler filename example.

    You can also change these two lines:

    mail($to,$email_subject,$email_body,$headers);
    return true;
    

    to:

    if(mail($to,$email_subject,$email_body,$headers)){ 
    echo "Mail sent successfully.";
    } 
    else{ echo "Error.";
    }
    

    If it echoes a success, then mail() has been successfully sent.

    If it echoes Error, then it's a server problem. Check your mail logs.

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

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系