我试图通过附件向此表单发送电子邮件,但我不确定如何

时间:2015-06-27 20:45:41

标签: php

请提供您的个人信息以及您的简历副本。          

名字:
    

    

姓氏:     

    

男     女

    

电话号码:     

    

电子邮件:     

    

地址:     

    

其他评论:     

    

您是否至少有一年的医疗/外科或遥测经验?

     是

    

护理水平:     LVN     RN     

    

选择要上传的简历:     

<input type="submit" value="Submit" name='submit'/>
</form>

1 个答案:

答案 0 :(得分:1)

这是HTML表单和PHP处理程序的测试/工作副本。这使用PHP mail()函数。

PHP处理程序还会将消息的副本发送给填写表单的人。

如果你不打算使用它,你可以在一行代码前面使用两个正斜杠//

例如: // $subject2 = "Copy of your form submission";将无法执行。

HTML表格:

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="mail_handler.php" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

PHP处理程序(mail_handler.php)

(使用HTML表单中的信息并发送电子邮件)

<?php 
if(isset($_POST['submit'])){
    $to = "email@example.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
    }
?>