我已经设置了一个phpmailer表单,它发送正常。但是当它到达电子邮件地址时,只会显示所发送邮件的第一个字母。例如,如果我将“来自联系人的测试消息”放入电子邮件的所有内容如下:
姓名:汤姆 电子邮件:tom@hotmail.com 电话: 主题:测试2 消息:T 2017年2月27日星期一,14:20:48
我已经尝试过查看代码,但不是那些知识渊博的PHP,无法看到问题。
有人可以帮助我吗?
这是表格
<form action="php/contact.php" method="post" enctype="multipart/form-data">
<fieldset>
<input type="hidden" name="action" value="contact_send" />
<div class="row">
<div class="form-group">
<div class="col-md-4">
<label for="contact:name">Full Name *</label>
<input required type="text" value="" class="form-control" name="contact[name][required]" id="contact:name">
</div>
<div class="col-md-4">
<label for="contact:email">E-mail Address *</label>
<input required type="email" value="" class="form-control" name="contact[email][required]" id="contact:email">
</div>
<div class="col-md-4">
<label for="contact:phone">Phone</label>
<input type="text" value="" class="form-control" name="contact[phone]" id="contact:phone">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label for="contact:subject">Subject *</label>
<input required type="text" value="" class="form-control" name="contact[subject][required]" id="contact:subject">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label for="contact:message">Message *</label>
<textarea required maxlength="10000" rows="8" class="form-control" name="contact[message]" id="contact:message"></textarea>
</div>
</div>
</div>
</fieldset>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-default"><i class="fa fa-check"></i> SEND MESSAGE</button>
</div>
</div>
</form>
这是contact.php
<?php
date_default_timezone_set('Etc/UTC');
@ini_set('display_errors', 0);
@ini_set('track_errors', 0);
require('config.inc.php');
if(isset($_POST['action']) && $_POST['action'] == 'contact_send') {
$email_body = null;
$array = $required = array();
$post_data = isset($_POST['contact']) ? $_POST['contact'] : null;
$is_ajax = (isset($_POST['is_ajax']) && $_POST['is_ajax'] == 'true') ? true : false;
if($post_data === null) {
if($is_ajax === false) {
_redirect('#alert_mandatory');
} else {
die('_mandatory_');
}
}
foreach($post_data as $key=>$value) {
$key_title = ucfirst($key);
$explode = @explode('_', $key_title);
if(!isset($explode[1]))
$explode = @explode('-', $key_title);
if(isset($explode[1])) {
$key_title = implode(' ', $explode);
$key_title = ucwords(strtolower($key_title));
}
if(isset($post_data[$key]['required'])) {
$required[] = $key;
if($key == 'name')
$array['name'] = $post_data[$key]['required'];
if($key == 'email')
$array['email'] = $post_data[$key]['required'];
$email_body .= "<b>{$key_title}:</b> {$post_data[$key]['required']} <br>";
} else {
$non_required[] = $key;
if($key == 'name')
$array['name'] = $post_data[$key];
if($key == 'email')
$array['email'] = $post_data[$key];
$email_body .= "<b>{$key_title}:</b> {$post_data[$key]} <br>";
}
}
foreach($required as $req) {
if(strlen(trim($post_data[$req]['required'])) < 1) { // changed from 2 to 1 [11:47 AM Saturday, June 18, 2016]
if($is_ajax === false) {
_redirect('#alert_mandatory');
exit;
} else {
die('_mandatory_');
}
}
}
$array['email'] = ckmail($array['email']);
if($array['email'] === false) {
if($is_ajax === false) {
_redirect('#alert_mandatory');
exit;
} else {
die('_mandatory_');
}
}
$ip = ip();
$date = date('l, d F Y , H:i:s');
$email_body .= "{$date} <br>";
if($config['use_smtp'] === true) {
require('phpmailer/5.2.10/PHPMailerAutoload.php');
require('phpmailer/5.2.10/class.phpmailer.php');
$m = new PHPMailer();
$m->IsSMTP();
$m->SMTPDebug = false; // enables SMTP debug information (for testing) [default: 2]
$m->SMTPAuth = true; // enable SMTP authentication
$m->Host = $config['smtp_host']; // sets the SMTP server
$m->Port = $config['smtp_port']; // set the SMTP port for the GMAIL server
$m->Username = $config['smtp_user']; // SMTP account username
$m->Password = $config['smtp_pass']; // SMTP account password
$m->SingleTo = true;
$m->CharSet = "UTF-8";
$m->Subject = $config['subject'];
$m->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$m->AddAddress($config['send_to'], $config['subject']);
$m->AddReplyTo($array['email'], isset($array['name']) ? $array['name'] : $array['email']);
$m->SetFrom($config['smtp_user'], isset($array['name']) ? $array['name'] : $array['email']);
$m->MsgHTML("
{$email_body}
---------------------------------------------------<br>
IP: {$ip}
");
if($config['smtp_ssl'] === true)
$m->SMTPSecure = 'ssl';
if($m->Send()) {
// die('sent');
if($is_ajax === false) {
_redirect('#alert_success');
exit;
} else {
die('_success_');
}
} else {
if($is_ajax === false) {
_redirect('#alert_failed');
exit;
} else {
die('_failed_');
}
}
} else {
mail(
$config['send_to'] ,
$config['subject'],
$email_body
);
if($is_ajax === false) {
_redirect('#alert_success');
exit;
} else {
die('_success_');
}
}
exit;
}
function _redirect($hash) {
$HTTP_REFERER = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
if($HTTP_REFERER === null)
die("Invalid Referer. Output Message: {$hash}");
header("Location: {$HTTP_REFERER}{$hash}");
exit;
}
function ckmail($email) {
$email = trim(strtolower($email));
if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/',trim($email))){
return $email;
} else { return false; }
}
function ip() {
if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }
elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); }
elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); }
elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); }
elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); }
else { $ip = $_SERVER['REMOTE_ADDR']; }
return $ip;
}
&GT;