1
したがって、フォームの90%を記入すると完全に機能するフォームをオンラインにしていますが、6/7残りのフィールドは電子メールで送信されません。私は数時間のグーグル・グーグルで、正しい問題を探したとは思わない。ここでは、実際にメール送信を行うコードは次のとおりです。フォームは空のフィールドの後に塗りつぶしフィールドを送信しません
$response = array();
$error = false;
$message = '';
if(empty($_POST) && !isset($_POST['send']))
{
$response['message'] = 'You have to submit the contact form first.';
$error = true;
}else{
unset($_POST['send']);
foreach($_POST as $key=>$val)
{
if($val == '')
{
$error = false;
$response['message'] = 'All fields are required';
break;
}
$message .= '<p>' . htmlspecialchars($key) . ': ' . htmlspecialchars($val) . '</p>';
}
}
if(!$error)
{
$subject = 'New message from Aguettant contact form';
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: [email protected]";
$headers[] = "Reply-To: {$_POST['Email']}";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
if(mail('[email protected]',$subject,$message,implode("\r\n", $headers)) !== FALSE)
{
// redirect
header("Location: thankyou.php");
die();
}else{
$response['message'] = 'Something went wrong. Please try again.';
}
私はそれが他/ foreachのに関係していることを判別しましたが、私はそれをコメントアウトした場合、私はコンテンツのない電子メールを取得します。
ああスナップ、これは働いた!それは常にその1行のコードです。ありがとう、@ヨルダン! – user964275