dongyongyin5339 2014-11-05 06:07
浏览 54
已采纳

PHP sendmail无法正常工作? [重复]

This question already has an answer here:

I have created a form for visitors of my website can message me if they want but for some reason it won't send the message and I do not know how to debug it.

Form:

<form method="post" action="sendmail.php">
                                <fieldset>
                                    <div class="form-group">
                                        <label for="firstname" class="sr-only">First Name</label>
                                        <input type="text" name="firstname" class="form-control" placeholder="First Name" id="firstname">
                                    </div>

                                    <div class="form-group">
                                        <label for="lastname" class="sr-only">Last Name</label>
                                        <input type="text" name="lastname" class="form-control" placeholder="Last Name" id="lastname">
                                    </div>

                                    <div class="form-group">
                                        <label for="email" class="sr-only">Email</label>
                                        <input type="text" name="email" class="form-control" placeholder="Email" id="email">
                                    </div>

                                    <div class="form-group">
                                        <label for="message" class="sr-only">Message</label>
                                        <textarea class="form-control" placeholder="Message" id="message"></textarea>
                                    </div>

                                    <input type="submit" class="btn btn-primary" value="Send Message" >


                                </fieldset>
                            </form>

and the sendmail.php for the info to be sent:

    <?php 
if(isset($_POST['submit'])){
    $to = "email@email.tld"; 
    $from = $_POST['email']; 
    $first_name = $_POST['firstname'];
    $last_name = $_POST['lastname'];
    $message = $firstname . " " . $last_name . " wrote the following:" . "

" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $firstname . "

" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$message,$headers);
    mail($from,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";

    }
?>
</div>
  • 写回答

1条回答 默认 最新

  • dpxkkhu1812 2014-11-05 06:12
    关注

    this is just an example format that you can try

    <?php 
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $business_name = $_POST['business_name'];
    $comment = $_POST['comment'];
    
    $from = 'From: abc'; 
    $to = ''; //email
    $subject = 'Customer Inquiry';
    $message = "From: $name
     Phone: $phone
     E-Mail: $email
     Business Name: $business_name
     Comment: $comment
     ";
    
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-type: text/html
    ";
    $headers = 'From: from@example.com' . "
    " .
    'Reply-To: reply@example.com' . "
    " .
    'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    header( "Location: abc" );//if u wish to get redirected
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?