使用php通过联系表单发送电子邮件时出现问题


Trouble sending email through contact form with php

我以前从未使用过php,我正试图在通过谷歌获得的一些php代码的帮助下使我的联系人表单发挥作用。

首先,我需要以某种方式将它链接到我的html页面(如css/javascript),还是如果它共享同一个文件夹,它会正常工作?

我已经修改了某些部分的名称以匹配我的html中的名称,但无法使其工作。当我点击提交按钮时,我会看到一个页面,上面写着。。。

"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "'n"; $Body .= "Company: "; $Body .= $Company; $Body .= "'n"; $Body .= "Email: "; $Body .= $Email; $Body .= "'n"; $Body .= "Deadline: "; $Body .= $Dealine; $Body .= "'n"; $Body .= "Interested: "; $Body .= $Interested; $Body .= "'n"; $Body .= "Message: "; $Body .= $Message; $Body .= "'n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print ""; } else{ print ""; } ?>

php代码如下。

<?php
$EmailFrom = "c@c.co.nz";
$EmailTo = "c@c.co.nz";
$Subject = "contact-form";
$Name = Trim(stripslashes($_POST['Name'])); 
$Company = Trim(stripslashes($_POST['Company'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Deadline = Trim(stripslashes($_POST['Dealine'])); 
$Interested = Trim(stripslashes($_POST['Interested'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "'n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "'n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "'n";
$Body .= "Deadline: ";
$Body .= $Dealine;
$Body .= "'n";
$Body .= "Interested: ";
$Body .= $Interested;
$Body .= "'n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "'n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page 
if ($success){
print "<meta http-equiv='"refresh'" content='"0;URL=contact-thanks.php'">";
}
else{
print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
}
?>

这是我的html

    <div role="form" class="form-wrapper">
<form name="contact-f" action="contact-form.php" method="post">
<div class="f-width">
<div class="f-col-1 f-group-1"><input type="text" name="Name" class="c-back input-t f-col-1" placeholder="Name" /></div>
<div class="f-col-1 f-group-2"><input type="email" name="Company" class="c-back input-t f-col-1" placeholder="Company Name" /></div>
<div class="f-col-1 f-group-1"><input type="text" name="Email" class="c-back input-t f-col-1" placeholder="Email Address" /></div>
<div class="f-col-1 f-group-2"><select name="Deadline" class="c-back input-t f-col-1"><option class="opt-f">Do you have a Deadline?</option><option value="Not yet" class="opt-f">Not yet</option><option value="Less than 1 Month" class="opt-f">Less than 1 Month</option><option value="2-3 Months" class="opt-f">2-3 Months</option><option value="3-6 Months" class="opt-f">3-6 Months</option><option value="6+ Months" class="opt-f">6+ Months</option></select></div>
<div class="f-col-2 f-group-3"><select name="Interested" class="c-back input-t f-col-2"><option class="opt-f">What are you interested in?</option><option value="Branding" class="opt-f">Branding</option><option value="Print Design" class="opt-f">Print Design</option><option value="Illustration" class="opt-f">Illustration</option><option value="Website / UI Design" class="opt-f">Website / UI Design</option><option value="Literature" class="opt-f">Literature</option><option value="Video Editing" class="opt-f">Video Editing</option><option value="Other" class="opt-f">Other</option></select></div>
<div class="f-col-3 f-group-4"><textarea name="Message" class="c-back input-t message-f f-col-3" placeholder="Describe your project..."></textarea></div>
<div class="f-submit f-group-5"><input type="Submit" name="Submit" value="Send" class="form-btn" /></div>
</div></form></div>

(是的,我已经创建了它最后调用的contact-thanks.php文件)。

这么多$Body,如何:

$Body = " Name : $Name 'n Company : $Company 'n Deadline : $Deadline 'n Interested : $Interested 'n Message : $Message";

这就是你想要的吗?