功能實現:經過中間郵箱把客戶的需求和產品信息所有發送到公司的業務員郵箱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