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

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

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等