zoukankan      html  css  js  c++  java
  • 42.PHP--电商网站的询价插件

    windows下使用php自带的mail函数实现简单的邮件发送实例(QQ亲试成功)

    功能实现:通过中间邮箱把客户的需求和产品信息全部发送到公司的业务员邮箱

    环境及工具:

    win7_64bit

    phpstudy(初学者推荐工具) 包含php5.3、sendmail(没有的话可网上下)

    两个QQ号 一个发一个收(我只有QQ邮箱,所以没测试其他邮箱,如163等)

    前台(HTML+css+js):

    <!-- Get quote popup start-->
    <div class="option-container">
    <style> @import "https://fonts.googleapis.com/css?family=Raleway";
    * { box-sizing: border-box; }
    body {
    margin: 0;
    padding: 0;
    background: #fff;
    font-family: Raleway;
    text-transform: uppercase;
    font-size: 11px;
    }
    h1{ margin: 0; }
    #contact {

    -webkit-user-select: none; /* Chrome/Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+ */
    margin: auto;
    padding: 5px 30px ;
    auto;
    height: auto;
    line-height: 30px;
    background: black;
    color: white;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    border: 1px solid white;
    }

    #contact:hover { background: #666; }
    #contact:active { background: #444; }

    #contactForm {
    z-index: 800;
    display: none;
    border: 2px solid #2979ff;
    box-shadow:2px 3px 15px #2979ff;
    padding: 10px;
    380px;
    text-align: center;
    background-color: #fff;
    position: fixed;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    -webkit-transform: translate(-50%,-50%)

    }
    .cf_regard{
    color:#2979ff;
    font-size:17px;
    }
    input, textarea {
    margin: .8em auto;
    font-family: inherit;
    text-transform: inherit;
    font-size: inherit;

    display: block;
    280px;
    padding: .4em;
    }
    textarea { height: 80px; resize: none; }

    .formBtn {
    140px;
    display: inline-block;

    background: black;
    color: #fff;
    font-weight: 100;
    font-size: 1.2em;
    border: none;
    height: 30px;
    }</style>
    <button class="btn btn-default" id="contact">Click to Enquiry</button>
    <div id="contactForm" style="">
    <h2 style="font-size:20px">Keep in touch!</h2>
    <form action="send.php" method="post">
    <input placeholder="Name" type="text" name="cf_name">
    <input placeholder="Email" type="email" name="cf_email">
    <input placeholder="Phone no." type="phone" name="cf_phone">
    <input placeholder="subject" type="text" name="cf_regard" class="cf_regard" >
    <textarea placeholder="Comment" cols="35" rows="5" name="cf_message"></textarea>
    <input class="formBtn" type="submit" value="submit" />
    <input class="formBtn" type="reset" value="reset"/>
    </form>
    </div>
    <script>
    $(function() {

    // contact form animations
    $('#contact').click(function() {
    $('#contactForm').fadeToggle();
    //Get product information
    var textName=$("#content h1").text();
    $(".cf_regard").val(textName);
    })
    $(document).mouseup(function (e) {
    var container = $("#contactForm");

    if (!container.is(e.target)
    && container.has(e.target).length === 0)
    {
    container.fadeOut();
    }
    });

    });
    </script>
    </div>
    <!-- Get quote popup end -->

    后台(PHP):

    <?php
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_phone = $_POST['cf_phone'];
    $field_regard = $_POST['cf_regard'];
    $field_message = $_POST['cf_message'];


    $mail_to = '2164792283@qq.com';
    $subject = 'product Name: ' .$field_regard.'';


    $body_message = 'User Name: ' .$field_name." ";
    $body_message .= 'User E-mail: ' .$field_email." ";
    $body_message .= 'User Phone: ' .$field_phone." ";
    $body_message .= 'User Subject: ' .$field_regard." ";
    $body_message .= 'User Message: ' .$field_message.'';

     


    $mail_status = mail($mail_to, $subject, $body_message);
    if ($mail_status) { ?>
    <script>
    alert('Thank you for your Enquiry. We will respond as soon as Possible');
    window.history.go(-1);
    </script>
    <?php
    }
    else { ?>
    <script>
    alert('Message failed. Please, send an email to 2164792283@qq.com ');
    </script>
    <?php
    }
    ?>

    环境配置文件:

    操作:

    1、需要用到mail函数,大家可以调用 http://localhost/phpinfo.php 来查看自己的服务器是否支持这个函数。

          这里mail邮件函数是 PHP 核心的组成部分。无需安装即可使用这些函数。

    2、作为邮件发送方的QQ必须开启SMTP服务,不开启是无法实现在php脚本中使用该QQ邮箱实现邮箱发送的。具体如何设置可到网上百度。

    php.ini :

    SMTP = smtp.zoho.com

    smtp_port =465

    sendmail_from = 2164792283@qq.com(公司业务员邮箱)

    sendmail_path ="C:PHPsendmailsendmail.exe -t"(sendmail对应地址,尽量越短越好!)

    sendmail只能在网上下载压缩文件,window系统没有。

    sendmail.ini:

    smtp_server=smtp.zoho.com  

    smtp_port=465

    smtp_ssl=auto

    auth_username= as0090@asicedirect.com(中间邮箱)
    auth_password= ######(中间邮箱的密码)

    force_sender= as0090@asicedirect.com

    error_logfile=error.log 建议开启(将前面的分号去掉),便于查找问题

    debug_logfile=debug.log 建议开启(将前面的分号去掉),便于查找问题

    总结:

    最终能实现发送邮件,但可以看到这些邮件都会被腾讯判定为垃圾邮件放到垃圾箱中,根据研究发现,也许是PHP的问题,最后可以把中间邮箱添加为好友,并修改备注,就不会被判定为垃圾邮箱。虽然我只是一名前端开发师,但是我有一个做全栈的梦!

    资料查询:

    菜鸟教程:http://www.runoob.com/php/php-ref-mail.html   

    opencart.com插件:https://www.opencart.com/index.php?route=marketplace/download&member_token=W5IE8x4gtAJsYHVgjk0eLmuzo5c47rtD&extension_id=32635&filter_license=0  

    W3C:http://www.w3school.com.cn/php/php_ref_mail.asp
    菜鸟教程:http://www.runoob.com/php/php-mail.html

  • 相关阅读:
    linux下安装jdk1.8
    在eclipse里面启动tomcat服务器时报错Server Tomcat v7.0 Server at localhost failed to start.
    frame使关闭口生效
    web.xml配置错误处理节点
    mac下修改mysql默认字符集为utf8
    Centos6.5关闭防火墙命令
    mysql修改
    java错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build
    完美解决Linux服务器tomcat开机自启动问题
    MAC 查看java home目录
  • 原文地址:https://www.cnblogs.com/sqyambition/p/8900553.html
Copyright © 2011-2022 走看看