首先按照百度经验的内容设定发送邮件服务器和diy.php代码,然后就要做邮件内容和表单匹配: 我们在自定义表单中设定了表单数据名,如下图:

在代码中我们就要设定表单对应的数据字段名,下面是我设定之前和设定之后的对比: 设定之前:

$query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar)  VALUES (NULL, 0 $addvalue); ";
$mailtitle = "用户订单信息"; //邮件标题
$mailbody = "称呼:{$name}\r\n邮箱:{$email}\r\n所在城市:{$city}\r\n国家:{$guojia}\r\n电话:{$tel}\r\n类别:{$qudao}";
$headers = $cfg_adminemail; //用我们刚才设置的管理员邮箱发送
$mailtype = 'TXT';   //邮件类型为文本类型
require_once(DEDEINC.'/mail.class.php'); //加载织梦的邮件库  
$smtp = new smtp($cfg_smtp_server,$cfg_smtp_port,true,$cfg_smtp_usermail,$cfg_smtp_password); //创建smtp服务
$smtp->debug = false; //不起用调试
$smtp->sendmail($cfg_smtp_usermail,$cfg_webname ,$cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype); //发送邮件

设定之后:

$query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar)  VALUES (NULL, 0 $addvalue); ";
$mailtitle = "用户订单信息";   //邮件标题
$mailbody = "称呼:{$name}\r\n邮箱:{$email}\r\n电话:{$phone}\r\nQQ:{$qq}\r\n留言内容:{$con}";
$headers = $cfg_adminemail;   //用我们刚才设置的管理员邮箱发送
$mailtype = 'TXT'; //邮件类型为文本类型
require_once(DEDEINC.'/mail.class.php');  //加载织梦的邮件库  
$smtp = new smtp($cfg_smtp_server,$cfg_smtp_port,true,$cfg_smtp_usermail,$cfg_smtp_password);//创建smtp服务
$smtp->debug = false; //不起用调试
$smtp->sendmail($cfg_smtp_usermail,$cfg_webname ,$cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);//发送邮件