提取dedecms邮件函数做到独立页

dedecms邮件发送只能用系统MAIL函数或者SMTP. 如果服务器是linux基本可不用配置任何SMTP信息。但是如果是windows机器,就必须配置SMTP。
我们配置SMTP会出现意外,比如用QQ邮局。织梦58测试发现
QQ邮箱:
1.  企业邮箱明显比QQ普通邮箱好用,不容易进入垃圾箱
2. QQ邮箱必须配置启用SMTP
3. SSL明显比不启用效率高

在DEDECMS关键词函数部分

require_once(dirname(__FILE__).'/../include/common.inc.php'); //在dedecms内必须引用

 

//邮件发送函数

function sendmail($email, $mailtitle, $mailbody)

{

global $cfg_sendmail_bysmtp, $cfg_smtp_server, $cfg_smtp_port, $cfg_smtp_usermail, $cfg_smtp_user, $cfg_smtp_password, $cfg_adminemail,$cfg_webname;

if($cfg_sendmail_bysmtp == 'Y' && !empty($cfg_smtp_server))

{

$mailtype = 'HTML';

require_once(DEDEINC.'/mail.class.php');

$smtp = new smtp($cfg_smtp_server,$cfg_smtp_port,true,$cfg_smtp_usermail,$cfg_smtp_password);

$smtp->debug = false;

if(!$smtp->smtp_sockopen($cfg_smtp_server)){

 ShowMsg('邮件发送失败,请联系管理员','-1');

   exit();

}

$smtp->sendmail($email,$cfg_webname,$cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);

}else{

@mail($email, $mailtitle, $mailbody, $headers);

}

}

在相应页面做以下代码

if(!$_POST) exit;

 

 

    $address = admin@@zuimoban.com';

$name   = $_POST['name'];

$mailto   = $_POST['email'];

$mailtitle   = $_POST['subject'];

    $mailbody = $_POST['message'];

 

$sendtime = time();

 

        

if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }

 

 

$msg  = "You have been contacted by $name with regards to $mailtitle.\r\n\n";

$msg .= "$mailbody\r\n\n";

$msg .= "You can contact $name via email, $mailto.\r\n\n";

$msg .= "-------------------------------------------------------------------------------------------\r\n";

 

 

if(@sendmail($address, $mailtitle, $msg, "From: $mailto\r\nReturn-Path: $mailto\r\n"))

{

echo "<p class='ajax_success'>Thanks for Contact Us.</p>";

}

else

{

echo "<p class='ajax_failure'>邮件发送成功</p>";

}

?>



再去包含个HTML页,就可以让用户通过邮件留言了

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e443873576b0c00de0b66f52c15e311f.html