我在从我的网站向我自己的Outlook.com帐户发送邮件时遇到问题,问题是如果有人使用我的联系表单,则不会将邮件发送给我。
通常情况下,PHP中的所有邮件进程都可以使用,但这次我想用它来使用JavaScript,所以我的表单会自动完成所有操作。我没有收到错误,我收到了发送电子邮件的消息。
//Contact script.
if(isset($_POST['submit']))
{
$sName = trim($_POST['author']);
$sEmail = trim($_POST['email']);
$sMessage = trim($_POST['comment']);
if(empty($sName))
{
$nameError = 'U bent uw naam vergeten';
$hasError = true;
}
if(empty($sEmail))
{
$emailError = 'U bent uw email adres vergeten';
$hasError = true;
}
elseif(!filter_var($sEmail, FILTER_VALIDATE_EMAIL))
{
$emailError = 'Uw mail adres is niet geldig!';
$hasError = true;
}
if(empty($sMessage))
{
$commentError = 'U hebt geen bericht opgegeven';
$hasError = true;
}
//Mail versturen.
if(!isset($hasError))
{
$weNaam = 'RASolutions';
$eiMail = 'info@rasolutions.nl';
$erMail = 'info@rasolutions.nl';
$nAfzender = 'RASolutions';
$afMail = '**********@.nl';
$baMail = 'info@seobeheer.nl';
$aHtml = true;
// De headers samenstellen
$headers = 'From: <' . $weNaam . '> '. PHP_EOL ;
$headers .= 'Reply-To: <' . $nAfzender . '> <' . $eiMail . '>' . PHP_EOL;
$headers .= ($baMail != '') ? 'Bcc: <' . $baMail . PHP_EOL : '';
$headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
$headers .= 'X-Priority: Normal' . PHP_EOL;
$headers .= ($aHtml) ? 'MIME-Version: 1.0' . PHP_EOL : '';
$headers .= ($aHtml) ? 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL : '';
$sBericht = "
Beste, <br />
<br />
er is gebruik gemaakt van het contact formulier op RASolutions.<br />
Het mail adres dat hiervoor is gebruikt: <strong>".$sEmail."</strong>, de naam van degene is <strong>".$sName."</strong>.<br />
<br />
<i>Onderstaande het bericht:</i>
".$sMessage."
<br /> <br />
Met vriendelijke groet, <br />
RASolutions helpdesk.
";
//Verzonden.
$mail = mail($afMail, "Contact || RASolutions", $sBericht, $headers);
$emailSent = true;
}
}
我的HTML表单和JS部分:
<?php
if(isset($emailSent) && $emailSent == true)
{
?>
<div class="succes closable">Uw mail is succesvol verstuurd! U zal in 48 uur een antwoord krijgen.</div>
<?php
}
if(isset($hasError) || isset($captchaError) )
{
?>
<div class="warning closable">Er zijn wat problemen opgetreden.</div>
<?php
}
?>
<form id="contact-us" action="" method="post">
<p>
<label for="author">Naam</label>
<input id="author" class="aqua_input" name="author" type="text" placeholder=""/>
</p>
<p>
<label for="email">Email</label>
<input id="email" class="aqua_input" name="email" type="email" placeholder=""/>
</p>
<p>
<label for="comment">Bericht</label>
<textarea id="comment" rows="8" class="aqua_input" name="comment" placeholder=""></textarea>
</p>
<p class="form-submit">
<input name="submit" type="submit" id="submit" value="Verstuur" class="sm_button">
</p>
</form>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function()
{
$('form#contact-us').submit(function()
{
$('.warning closable').remove();
var hasError = false;
$('.aqua_input').each(function()
{
if($.trim($(this).val()) == '')
{
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="warning closable">U bent uw '+labelText+' vergeten op te geven</div>');
$(this).addClass('inputError');
hasError = true;
}
else if($(this).hasClass('email'))
{
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($.trim($(this).val())))
{
var labelText = $(this).prev('label').text();
$(this).parent().append('<div class="warning closable"><strong>Helaas!</strong> Uw ingevoerde waardes zijn ongeldig: '+labelText+'</div>');
$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError)
{
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data)
{
$('form#contact-us').slideUp("fast", function()
{
$(this).before('<div class="success closable"><strong>Bedankt!</strong> U zal in 48 uur een antwoord krijgen. </div>');
});
});
}
return false;
});
});
//-->!]]>
</script>
答案 0 :(得分:0)
$mail = mail($afMail, "Contact || RASolutions", $sBericht, $headers);
$emailSent = true;
不要这样做,而是检查$mail
值,它是函数的结果,是真还是假。
然后,如果你单独尝试php方面,它是否有效?
就像你这样运行它一样:
<?php
$_POST['author'] = 'asdasdas';
$_POST['email'] = 'asdasd@free.fr';
$_POST['comment'] = 'asdasd';
if (1 || isset($_POST['submit'])) {
$sName = trim($_POST['author']);
$sEmail = trim($_POST['email']);
$sMessage = trim($_POST['comment']);
if (empty($sName)) {
$nameError = 'U bent uw naam vergeten';
$hasError = true;
}
if (empty($sEmail)) {
$emailError = 'U bent uw email adres vergeten';
$hasError = true;
} elseif (!filter_var($sEmail, FILTER_VALIDATE_EMAIL)) {
$emailError = 'Uw mail adres is niet geldig!';
$hasError = true;
}
if (empty($sMessage)) {
$commentError = 'U hebt geen bericht opgegeven';
$hasError = true;
}
//Mail versturen.
if (!isset($hasError)) {
$weNaam = 'RASolutions';
$eiMail = 'info@rasolutions.nl';
$erMail = 'info@rasolutions.nl';
$nAfzender = 'RASolutions';
$afMail = '**********@.nl';
$baMail = 'info@seobeheer.nl';
$aHtml = true;
// De headers samenstellen
$headers = 'From: <' . $weNaam . '> ' . PHP_EOL;
$headers .= 'Reply-To: <' . $nAfzender . '> <' . $eiMail . '>' . PHP_EOL;
$headers .= ($baMail != '') ? 'Bcc: <' . $baMail . PHP_EOL : '';
$headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
$headers .= 'X-Priority: Normal' . PHP_EOL;
$headers .= ($aHtml) ? 'MIME-Version: 1.0' . PHP_EOL : '';
$headers .= ($aHtml) ? 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL : '';
$sBericht = "
Beste, <br />
<br />
er is gebruik gemaakt van het contact formulier op RASolutions.<br />
Het mail adres dat hiervoor is gebruikt: <strong>" . $sEmail . "</strong>, de naam van degene is <strong>" . $sName . "</strong>.<br />
<br />
<i>Onderstaande het bericht:</i>
" . $sMessage . "
<br /> <br />
Met vriendelijke groet, <br />
RASolutions helpdesk.
";
//Verzonden.
$mail = mail($afMail, "Contact || RASolutions", $sBericht, $headers);
var_dump($mail);
$emailSent = true;
}
}
答案 1 :(得分:0)
$.post($(this).attr('action'),formInput, function(
我想$(this).attr('action')
这里是空的,js不知道在哪里发布数据。将此值替换为发布数据的实际路径。
您还在检查浏览器控制台中是否有任何错误(F12)?