douyueju2912 2017-01-03 04:18
浏览 41

你可以在bootstrap页面上做一个PHP联系表单而不使用div和表单类吗?

i am not running this locally, i am running/debugging the issue live

what i mean is, a lot of the examples ive seen seem to have too much markup in them. i am trying to accomplish implementing a simple contact form, and my PHP seems to run just fine, it displays the alert on submit, but its not sending the email. I am not sure if its due to my PHP, but it seems to compile just fine.

Is there an issue with the way these 2 are wiring up?

HTML snip:

<form id="contactForm" class="" role="form" method="post"   action="contactHandler2.php">

     <input id="name" type="text" placeholder="NAME" name="name">

     <input class="input-twin" id="email" name="email" type="text" placeholder="E-MAIL">

     <input type="tel" class="input-twin" name="phone" placeholder="PHONE">

     <select name="focus" id="contact-focus">
        <option value="" disabled selected>Interested In...</option>
        <option value="v0">Opt1 Inquiry</option>
        <option value="v1">Opt2</option>
        <option value="v2">Opt3</option>
     </select>

     <textarea id="message" name="message" type="text" placeholder="Details, Availability, Questions, etc"></textarea>

     <input id="submit" type="submit" value="GO!">

</form>

PHP:

<?php

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



// EDIT THE 2 LINES BELOW AS REQUIRED

$email1 = "myemail@gmail.com";
$email2 = "myotheremail@gmail.com";

$email_subject = "PT Website Inquiry";





function died($error) {

    // your error code can go here

    echo "We are very sorry, but there were error(s) found with the form you submitted. ";

    echo "These errors appear below.<br /><br />";

    echo $error."<br /><br />";

    echo "Please go back and fix these errors.<br /><br />";

    die();

}



// validation expected data exists

    if(!isset($_POST['name']) || !isset($_POST['email']) ||     !isset($_POST['message'])) {

    died('We apologize, but something weird happened. Please try again.');

}

$name = $_POST['name']; //

$email_from = $_POST['email']; //

$phone = $_POST['phone']; //

$focus = $_POST['focus'];

$message = $_POST['message']; //


$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

 if(!preg_match($email_exp,$email_from)) {

 $error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(strlen($message) < 2) {

 $error_message .= 'The message you entered do not appear to be valid.  <br />';

 }

if(strlen($error_message) > 0) {

  died($error_message);

 }

$email_message = "Someone submitted our website's contact form, here are the details:

";



function clean_string($string) {

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

 }



$email_message .= "Name: ".clean_string($name)."
";

$email_message .= "Email: ".clean_string($email_from)."
";

$email_message .= "Phone: ".clean_string($phone)."

";

$email_message .= "They expressed interest in: ".clean_string($focus)."

";

$email_message .= "Message: 

".clean_string($message)."

";


$email_message .= "****************

                   DO NOT REPLY

                   ****************";


// create email headers

$headers = 'From: '.$email_from."
".

'Reply-To: '.$email_from."
" .

'X-Mailer: PHP/' . phpversion();

mail($email1, $email_subject, $email_message, $headers);
mail($email2, $email_subject, $email_message, $headers);


// header('Location: http://allcalrecycling.com');

echo "<script>
alert('Thank you! We will reach out shortly.');
window.location.href='index.html';
</script>";


?>


<?php

 }

?>
  • 写回答

2条回答 默认 最新

  • drxyaox153896 2017-01-03 04:32
    关注

    Check your hosting mail service. You can try this library PHPMailer it easy to configurable send email using SMTP

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类