如何将表单发送到电子邮件

时间:2016-02-07 13:02:51

标签: php email

嘿伙计们,我正在尝试将表格发送到电子邮件,这是我的表格:

<?php 
error_reporting(0);
if(isset($_POST['submit'])){
    $to = "elbiheiry2@gmail.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.
    }
?>

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

<form action="form.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>
Image: <input type="file" name="image_name"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html> 

每次我点击提交它告诉我邮件已发送但当我检查我的收件箱时我发现没有人可以帮助???

1 个答案:

答案 0 :(得分:0)

我建议您切换到PHPMailer,它将为您处理电子邮件配置。