我是PHP的菜鸟。当我发送邮件时,我只收到有关以下内容的信息:他们的姓名和电子邮件地址。
我知道这可能很简单,但我还没有花时间去完全学习PHP,希望得到答案! :)
我的PHP:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_adress = $_POST['cf_adress'];
$field_post = $_POST['cf_post'];
$field_radio = $_POST['cf_radio'];
$mail_to = 'myemailadress@dsadsadsa.dsa';
$subject = 'Order from website - '.$field_name;
$body_message = 'From: '.$field_name."\n"; <--- This one
$body_message .= 'E-mail: '.$field_email."\n"; <--- and this one is the only fields i get in the mails :/
$body_message .= 'Adresse: '.$field_adress."\n";
$body_message .= 'Postnr/Sted: '.$field_post."\n";
$body_message .= 'Størrelse: '.$field_radio."\n";
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Success!');
window.location = 'produkt.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('something is wrong...');
window.location = 'websiteadress';
</script>
<?php
}
?>
我的HTML标记:
<form action="contact.php" method="post" onsubmit="return validateForm();">
<div id="contentorder">
<div class="pink">
Fornavn og Etternavn<br />
</div>
<div class="black">
<input type="text" name="cf_name" required style="width: 260px; height: 20px;">
</div>
</div>
<div id="contentorder">
<div class="pink">
E-Mail
</div>
<div class="black">
<input type="text" name="cf_email" required style="width: 260px; height: 20px;">
</div>
</div>
<div id="contentorder">
<div class="pink">
Postadresse
</div>
<div class="black">
<input type="text" name="cf_adress" required style="width: 260px; height: 20px;">
</div>
</div>
<div id="contentorder">
<div class="pink">
Postnummer og Sted<br />
</div>
<div class="black">
<input type="text" name="cf_post" required style="width: 260px; height: 20px;">
</div>
</div>
<div id="contentorder">
<div class="pink" style="width: 890px; margin-top: 20px; clear: both; ">
Størrelse:<br />
</div>
<div class="radio-toolbar">
<input type="radio" id="radio1" name="cf_radio" value="XS" checked required>
<label for="radio1">XS</label>
<input type="radio" id="radio2" name="cf_radio" value="S" required>
<label for="radio2">S</label>
<input type="radio" id="radio3" name="cf_radio" value="M" required>
<label for="radio3">M</label>
<input type="radio" id="radio4" name="cf_radio" value="L" required>
<label for="radio4">L</label>
<input type="radio" id="radio5" name="cf_radio" value="XL" required>
<label for="radio5">XL</label>
<input type="radio" id="radio6" name="cf_radio" value="XXL" required>
<label for="radio6">XXL</label>
</div>
</div>
<div id="contentorder">
<input type="submit" value="Send" class="buttonbest">
</div>
</form>
答案 0 :(得分:1)
你的代码对我来说非常好。
我猜你在$ body_message的地址(或其他字段)中有特殊字符。
例如:
$body_message .= 'Adresse: '.$field_adress."\n";
如果$ field_adress是“Godric's Hollow”,你最终会得到“Godric”,而且很可能会被忽略。确保在操作它们之前转义每个$ _POST字段。