联系表单提交,用于在csv中发送电子邮件和记录数据

问题描述 投票:0回答:1

我有一个联系表单,在提交时会显示一条感谢信息,将用户输入并通过电子邮件发送到一个地址,但也应该将四个字段放入CSV中。不幸的是,无论我尝试什么,我都无法完成最后一部分工作。

感谢消息有效,发送了一封电子邮件,但我在$output(在if / else之前)添加的部分没有。

这是我正在使用的代码,提前感谢任何可以提供帮助的人。

<?php

$subject = 'Submission received'; 
$mailto  = ''; 

$firstName      = $_POST['firstName'];
$lastName       = $_POST['lastName'];
$email          = $_POST['email'];
$telephone      = $_POST['telephone'];
$company        = $_POST['companyName'];
$country        = $_POST['country'];
$about          = $_POST['hearAbout'];
$enquiry        = $_POST['enquiry'];

$body = "
<br>
<p>The following information was submitted through the contact form on your website:</p>
<p><b>Name</b>: $firstName $lastName<br>
<b>Email</b>: $email<br>
<b>Phone number</b>: $telephone</br>
<b>Company name</b>: $company<br>
<b>Country</b>: $country<br>
<b>Heard about company via</b>: $about<br>
<b>Enquiry</b>: $enquiry<br></p>
";

// Success Message - PAD THIS OUT
$success = "
<div class=\"\">
    <div class=\"\">
        <h3>Submission successful</h3>
        <p>Thank you.</p> 
    </div>
</div>
";

$headers = "From: $firstName $lastName <$email> \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>$body</body></html>";

$output = $firstName . "t";
$output .= $lastName . "t";
$output .= $email . "t";
$output .= $telephone . "n";
$fp = fopen("data/enquiry.csv", "a");
fwrite($fp, $output);
fclose($fp);

if (mail($mailto, $subject, $message, $headers)) {
        echo "$success"; // success
} else {
    echo 'Form submission failed. Please try again...'; // failure
}
?>
php forms csv contact
1个回答
0
投票

也许这会有所帮助:

$fp = fopen("data/enquiry.csv", "a");
fwrite($fp,"," . $firstName . "," . $lastName . "," . $email . "," . $telephone . "\n");
fclose($fp);
© www.soinside.com 2019 - 2024. All rights reserved.