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

yipeiwu_com5年前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程序设计有所帮助。

相关文章

刚才在简化php的库,结果发现很多东西

php的ming库用来生成flash!虽然模块是试验性质的, 不过比较有趣。一张大大的表, 很有趣, 给人一种在8g的感觉。 sapi/php4activescript.dll (p...

php简单浏览目录内容的实现代码

如下所示:复制代码 代码如下:<?php$dir = dirname(__FILE__);$open_dir = opendir($dir);echo "<table bor...

PHP 遍历文件实现代码

复制代码 代码如下: function Files($path) { foreach(scandir($path) as $line) { if($line=='.'||$line=='...

php实现将字符串按照指定距离进行分割的方法

本文实例讲述了php实现将字符串按照指定距离进行分割的方法。分享给大家供大家参考。具体如下: 将一个字符串每隔三个字符添加一个逗号,例如把字符串1234567890转换为1,234,56...

利用curl 多线程 模拟 并发的详解

首先,先了解下 php中的curl多线程函数:复制代码 代码如下:# curl_multi_add_handle# curl_multi_close# curl_multi_exec#...