php提交表单发送邮件的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php提交表单发送邮件的方法。分享给大家供大家参考。具体如下:

保存下面的html代码到:email.html文件

<html>
<head>
<title>Simple Send Mail </title>
</head>
<body>
<h1>Mail Form</h1>
<form name="form1" method="post" action="mail.php">
<table>
   <tr><td><b>To</b></td><td>
   <input type="text" name="mailto" size="35">
   </td></tr>
   <tr><td><b>Subject</b></td>
     <td><input type="text" name="mailsubject" size="35"></td>
   </tr>
   <tr><td><b>Message</b></td>
     <td>
  <textarea name="mailbody" cols="50" rows="7"></textarea>
  </td>
   </tr>
   <tr><td colspan="2">
      <input type="submit" name="Submit" value="Send">
     </td>
   </tr>
  </table>
</form>
</body>
</html>

后端php代码,保存到mail.php

<?php
  if (empty ($_POST['mailto']) ) {
    die ( "Recipient is blank! ") ;
  }
  if (empty ($_POST['$mailsubject']) ){
    $mailsubject=" " ;
  }
  if (empty ($_POST['$mailbody']) ) {
    $mailbody=" " ;
  }
  $result = mail ($mailto, $mailsubject, $mailbody) ;
  //send the email
  if ($result) {
    echo "Email sent successfully!" ;
  }else{
    echo "Email could not be sent." ;
  }
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHPExcel中文帮助手册|PHPExcel使用方法(分享)

下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include...

php截取后台登陆密码的代码

if($_POST[loginsubmit]!=){ //判断是否点了登陆按钮 $sb=user:.$_POST[username].--passwd:.$_POST[password]...

PHP函数spl_autoload_register()用法和__autoload()介绍

__autoload()的用法就不再说了,以前已经在我的WEB开发笔记中说过。PHP __autoload函数(自动载入类文件)的使用方法, 原文地址:https://www.jb51....

php实现的在线人员函数库

//增加用户      function AddUser($username){    &nb...

深入探讨PHP中的内存管理问题

深入探讨PHP中的内存管理问题

一、 内存  在PHP中,填充一个字符串变量相当简单,这只需要一个语句"<?php $str = 'hello world '; ?>"即可,并且该字符串能够被自由地修改、拷贝和移动。而...