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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测