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 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用