我是PHP的新手,我建立了一个简单的联系表。
我可以正确地从中接收信息,但是当要重播到电子邮件时,不会采取此操作(我必须手动输入)。
我仔细检查过,没有看到错误。
我尝试过的是这个
“回复至:”。 $ email
这是我的PHP代码
<?php
/*
* CONFIGURE EVERYTHING HERE
*/
// an email address that will be in the From field of the email.
$from = 'Kontaktformular <email>';
// an email address that will receive the email with the output of the form
$sendTo = 'Kontaktformular | <mail@mydomain.com>';
// subject of the email
$subject = 'Message | domain.com';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Name', 'surname' => 'Vorname', 'phone' => 'Phone', 'email' => 'E-mail', 'message' => 'Nachricht');
// message that will be displayed when everything is OK :)
$okMessage = 'Danke für Ihre KontaktaufnahmeWir melden uns in Kürze bei Ihnen.';
// If something goes wrong, we will display this message.
$errorMessage = 'Error';
/*
* LET'S DO THE SENDING
*/
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText = "Nachricht | mydomain.com\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if ($responseArray['type'] == 'success') {
// success redirect
}
else {
//error redirect
}
我的HTML
<form id="contact-form" method="post" action="/assets/forms/contact_form.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Name *</label>
<input id="form_name" type="text" name="name" class="form-control" placeholder="Name *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_lastname">Lastname *</label>
<input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Vorname *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Email *</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="E-Mail *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="form_message">Nachricht *</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Nachricht *" rows="4" required="required" data-error="Please, leave us a message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12">
<div class="g-recaptcha" data-sitekey=""></div>
<input type="submit" class="btn btn-success btn-send" value="Senden">
</div>
</div>
</div>
</form>
重点是:我收到了联系表中的电子邮件,但无法重播。我可以,但是我必须手动输入电子邮件。看来“重播到”功能无法正常工作。
预先感谢