42.PHP--电商网站的询价插件

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

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

环境及工具:css

win7_64bithtml

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

两个QQ号 一个发一个收(我只有QQ邮箱,因此没测试其余邮箱,如163等)web

前台(HTML+css+js):windows

<!-- 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 { api

-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
margin: auto;
padding: 5px 30px ;
width: 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;
width: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;
width: 280px;
padding: .4em;
}
textarea { height: 80px; resize: none; }

.formBtn {
width: 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."\n";
$body_message .= 'User E-mail: ' .$field_email."\n";
$body_message .= 'User Phone: ' .$field_phone."\n";
$body_message .= 'User Subject: ' .$field_regard."\n";
$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
}
?>

环境配置文件:

操做:

一、须要用到mail函数,你们能够调用 http://localhost/phpinfo.php 来查看本身的服务器是否支持这个函数。

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

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

php.ini :

SMTP = smtp.zoho.com

smtp_port =465

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

sendmail_path ="C:\PHPsendmail\sendmail.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

相关文章
相关标签/搜索