使用php函数sendmail发送带附件的邮件

时间:2012-06-12 20:44:57

标签: php

我有一个这样的表格:

这是1.php

<form action="2.php" method="post">
Name: <input type="text" name="name" /></br>
Email: <input type="text" name="email" />
<input type="submit" value="Submit" />

比2.php是这样的:

<form action="3.php" method="post">
<input type="hidden" name="name" value="<?php echo $_POST['name'];?>"/>
<input type="hidden" name="email" value="<?php echo $_POST['email'];?>"/>
Telephone: <input type="text" name="telephone" /></br>
Location: <input type="text" name="location" />
<input type="submit" value="Submit" />

和最后一个3.php是这样的:

<?php
    $error = "";
    if(isset($_POST['submit'])) {
        if(empty($_POST['email']) || empty($_POST['name'])) {
            $error .= 'There is an error. Retry.  <br />';
        }
        if(!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {
            $error .= 'E-mail is incorrect. <br />';
        }       
        function sendmail() {
            $to = 'user@domain.tld';
            $name = "Name : " .$_POST['name'];
            $telephone = "Telephone : " . $_POST['telephone']. "";
            $location = "Location : " .$_POST['location'];
            $subiect = "Form from webpage";
            $body = 'form content: '. $name. "\n". $telephone. "\n\n" . $location. "\n\n". $from ;
            $from = "From: " . $_POST['email']. "";
            if(mail($to,$subiect,$body,$from)) {
              echo '<p>Thank you !</p><br />';
            }else{
              echo '<p>Error with server</p>';
            }
        }
        if($error == "") {
           sendmail();
        }
        echo "<p>".$error."</p>";
    }            
?>

我的问题是如何在第一页中引入<input type="file" name="file" id="file" />,当用户可以上传照片,然后在3.php页面上,当他点击提交按钮时,该图片将在电子邮件

可以有人给我一个例子吗?谢谢!

0 个答案:

没有答案