发送电子邮件无法使用 Bootstrap [重复]

send email is not working with bootstrap [duplicate]

提问人:jismtu 提问时间:7/22/2015 最后编辑:PHPhiljismtu 更新时间:7/22/2015 访问量:1100

问:

当您使用 Boothstrap 填写“联系我们”表格时,我正在尝试发送电子邮件。我收到一封电子邮件,但其中没有信息的空电子邮件已填写。请帮助我哪里出错了。

这是我的PHP。

<?
if(isset($_POST['sendemail'])) {     

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "[email protected]";

$email_subject = "General Inquery";
$name = $_POST['name']; 
$email = $_POST['email']; 
$subject =$_POST['subject']; 
$message = $_POST['message'];      

function clean_string($string) {

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

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

}
$email_message .= "First Name: ".clean_string($name)."\n";    

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

$email_message .= "subject: ".clean_string($subject)."\n";

$email_message .= "message: ".clean_string($message)."\n";

$headers = 'From: '.$email_from."\r\n".

   'Reply-To: '.$email_from."\r\n" .

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

   @mail($email_to, $email_subject, $email_message, $headers);  

?>

The HTML:

<section id="contact-page">
    <div class="container">
        <div class="center">        
            <h2>Drop Your Message</h2>
            <p class="lead">Please feel free to contact us if you have any query.</p>
        </div> 
        <div class="row contact-wrap"> 
            <div class="status alert alert-success" style="display: none"></div>
            <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                <div class="col-sm-5 col-sm-offset-1">
                    <div class="form-group">
                        <label>Name *</label>
                        <input type="text" name="name" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Email *</label>
                        <input type="email" name="email" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Phone</label>
                        <input type="number" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>Company Name</label>
                        <input type="text" class="form-control">
                    </div>                        
                </div>
                <div class="col-sm-5">
                    <div class="form-group">
                        <label>Subject *</label>
                        <input type="text" name="subject" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Message *</label>
                        <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
                    </div>                        
                    <div class="form-group">
                        <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
                    </div>
                </div>
            </form> 
        </div><!--/.row-->
    </div><!--/.container-->
</section><!--/#contact-page-->
PHP HTML 表单 twitter-bootstrap 电子邮件

评论

1赞 Rob 7/22/2015
$first_name 设置在哪里?
1赞 Rob 7/22/2015
看起来不像。您有 $name = $_POST['name'],但在 clean_string() 函数中使用 $first_name 作为参数。所有 clean_string() 参数均未在任何地方设置。
0赞 jmoerdyk 7/22/2015
您需要包含您的代码<form>
1赞 Rob 7/22/2015
$email_from 设置在哪里?
1赞 Rob 7/22/2015
除了你的代码充斥着错误的变量设置之外,它应该没问题。你只需要看看你的代码。

答:

0赞 PHPhil 7/22/2015 #1

我不认为,这是你的完整代码,但我可以看到你从未设置过,所以永远不会是真的。$_POST['sendemail']if(isset($_POST['sendemail'])) {

编辑

看看下面的代码,我做了 3 条评论。

<?php
// 1. -------------↓ Change sendemail to submit
if(isset($_POST['submit'])) {         

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "[email protected]";

$email_subject = "General Inquery";
$name = $_POST['name']; 
$email = $_POST['email']; 
$subject =$_POST['subject']; 
$message = $_POST['message'];      

function clean_string($string) {

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

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

}

// 2. --↓  Add $email_message = '';
$email_message = '';    
$email_message .= "First Name: ".clean_string($name)."\n";

// 3. -------------------------------------↓   Change $email_from to $email     
$email_message .= "Email: ".clean_string($email)."\n";    
$email_message .= "subject: ".clean_string($subject)."\n";    
$email_message .= "message: ".clean_string($message)."\n";    
echo "message: " . $email_message . "<br>";
}

?>

评论

0赞 PHPhil 7/22/2015
@jismtu 没有真正描述任何更改,只是指出了代码失败的点之一。编辑了我的答案。
0赞 PHPhil 7/22/2015
@jismtu 仅仅告诉我们“未定义”并没有真正的帮助。至少告诉我们哪个变量是未发现的。
0赞 PHPhil 7/22/2015
@jismtu编辑了我的答案,我指出了您应该更改/添加的 3 件事。查看您的网站无济于事。我在那里看不到你的 php 代码。
0赞 jismtu 7/22/2015
现在继续显示电子邮件正在发送。
0赞 PHPhil 7/23/2015
@jismtu真的帮不了你,我只能看你提供的代码。