dpqy77560 2014-05-01 21:25
浏览 35
已采纳

如何配置联系表单以接收邮件

I am trying to configure my contact from to my remote server. The technical guys from my hosting have issued me this settings for my mail setting:

(POP3/IMAP) & outgoing mail (SMTP) server name is: mail.yourdomain.com ports are: POP3 -> 110, IMAP -> 143 and SMTP -> 25 or 2525

Unfortunately, i do not know where to insert that into my php contact file.

these are the contact files:

contact.html

<form role="form" action="contact.php" method="post">
                                                <div class="text-fields">
                                                        <div class="form-group">
                                                                <input type="text" class="form-control" name="bbname" id="bbname" placeholder="name:">
                                                        </div>
                                                        <div class="form-group">
                                                                <input type="email" class="form-control" name="bbemail" id="bbemail" placeholder="email:">
                                                        </div>
                                                        <div class="form-group">
                                                                <input type="text" class="form-control" name="bbphone" id="bbphone" placeholder="phone:">
                                                        </div>
                                                </div>
                                                <div class="submit-area">
                                                        <div class="form-group">
                                                                <textarea class="form-control" placeholder="message:" name="bbmessage" id="bbmessage"></textarea>
                                                        </div>
                                                        <button type="submit" class="btn btn-default" id="bbsubmit">Send it</button>
                                                </div>
          </form>

contact.php

<?php
$field_name = $_POST['bbname'];
$field_email = $_POST['bbemail'];
$field_phone = $_POST['bbphone'];
$field_message = $_POST['bbmessage'];

$mail_to = 'me@mydomain.com';
$subject = 'Message from '.$field_name;

$body_message = 'From: '.$field_name."
";
$body_message .= 'E-mail: '.$field_email."
";
$body_message .= 'Phone: '.$field_phone."
";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."
";
$headers .= 'Reply-To: '.$field_email."
";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. I will contact you shortly.');
        window.location = 'contact.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to me@mail.com');
        window.location = 'contact.html';
    </script>
<?php
}
?>
  • 写回答

1条回答 默认 最新

  • douzhuoxia0587 2014-05-01 21:49
    关注

    I advise you rather use ready Mailer class for that - http://phpmailer.worxware.com/ is the best choice. I use it for many years and you can configure SMTP connection very easy

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上