我的网站上有一个php联系表格。但是,当我的客户输入他们的电子邮件地址并提交他们的消息时,我收到了对我自己的电子邮件的回复。例如,如果他们输入adam@yahoo.com我收到电子邮件为myusername@myhostingprovider.com ....如何解决这个问题,以便回复部分显示客户输入的电子邮件?谢谢。
以下是我的联系表格的代码
<form action="php/contact.php" method="post" class="contactForm" id="contactForm">
<fieldset>
<div class="formValidationError bg-red-dark color-white" id="contactNameFieldError">
<p class="center-text uppercase small-text">Name is required!</p>
</div>
<div class="formValidationError bg-red-dark color-white" id="contactEmailFieldError">
<p class="center-text uppercase small-text">Mail address required!</p>
</div>
<div class="formValidationError bg-red-dark color-white" id="contactEmailFieldError2">
<p class="center-text uppercase small-text">Mail address must be valid!</p>
</div>
<div class="formValidationError bg-red-dark color-white" id="contactMessageTextareaError">
<p class="center-text uppercase small-text">Message field is empty!</p>
</div>
<div class="formFieldWrap">
<label class="field-title contactNameField" for="contactNameField">Name:<span>(required)</span></label>
<input type="text" name="contactNameField" value="" class="contactField requiredField" id="contactNameField"/>
</div>
<div class="formFieldWrap">
<label class="field-title contactEmailField" for="contactEmailField">Email: <span>(required)</span></label>
<input type="text" name="contactEmailField" value="" class="contactField requiredField requiredEmailField" id="contactEmailField"/>
</div>
<div class="formTextareaWrap">
<label class="field-title contactMessageTextarea" for="contactMessageTextarea">Message: <span>(required)</span></label>
<textarea name="contactMessageTextarea" class="contactTextarea requiredField" id="contactMessageTextarea"></textarea>
</div>
<div class="formSubmitButtonErrorsWrap">
<input type="submit" class="buttonWrap button button-grey contactSubmitButton" id="contactSubmitButton" value="SUBMIT" data-formId="contactForm"/>
</div>
</fieldset>
</form>
此处还有PHP脚本的代码
<?php
// variables start
$name = "";
$email = "";
$message = "";
$name = trim($_POST['contactNameField']);
$email = trim($_POST['contactEmailField']);
$message = trim($_POST['contactMessageTextarea']);
// variables end
// email address starts
$emailAddress = 'myemail@yahoo.com';
// email address ends
$subject = "Mywebsite.com | Mobile - Message From: $name";
$message = "<strong>From:</strong> $name <br/> <strong>E-Mail:</strong> $email </br><br/> <strong>Message:</strong> $message";
$headers = 'From: '. $name . '<' . $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";
//send email function starts
mail($emailAddress, $subject, $message, $headers);
//send email function ends
&GT;
答案 0 :(得分:0)
在您的代码中,您还没有添加到标题字符串中,您每次都重置它。 你最后发送到header变量中的mail函数的只是;
'内容类型:text / html; charset = iso-8859-1'。为 “\ r \ n” 个
您需要做的是设置$ headers =的位置,更改等号以使其看起来像这个$ headers。=
因为这意味着它将添加到String。或者,只需将其格式化为一个巨大的字符串。
<?php
$headers = 'From: '. $name . '<' . $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";
//send email function starts
mail($emailAddress, $subject, $message, $headers);