我不能用php发送邮件
我的代码是:我不能用php发送邮件,php,email,Php,Email,我的代码是: <?php if(isset($_POST['submit'])){ //veryfing the name if(empty($_POST['name'])){ ?> <div class="alert alert-danger alert-dismissable"><button type="button" class
<?php
if(isset($_POST['submit'])){
//veryfing the name
if(empty($_POST['name'])){ ?>
<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter your name .</div>
<?php}
else{
$name = htmlentities($_POST['name']);
}
//veryfing the email
if(empty($_POST['email'])) { ?>
<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter your email .</div>
<?php}
else if(filter_var($_POST['email'] , FILTER_VALIDATE_EMAIL === false)){ ?>
<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter a valid email .</div>
<?php }
else{
$email ="<". htmlentities($_POST['email']).">";
}
if(empty($_POST['message'])){?>
<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>PLease enter some message .</div>
<?php}
else{
$message = htmlentities($_POST['message']);
}
if(empty($_POST['name'] ) or empty( $_POST['email']) or empty($_POST['message']) ){?>
<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Something went wrong ! .</div>
<?php}
else{
$headers = 'From: {$email}' . "\r\n" .
'Reply-To: {$email}' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail("seiramami12@gmail.com" , "An email from Omarmannan.net" , $message , $headers);
}
if(!$send_mail){?>
<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>Something went wrong ! .</div>
<?php }
else{
echo '<div class="alert alert-success">Email successfully sent. Thank you for your message.</div>';
}
}?>
请输入您的姓名。
×请输入您的电子邮件。
×请输入有效的电子邮件。
请输入一些消息。
某处出了问题。
某处出了问题。
但是我不能发邮件。我一直在使用我自己的个人网站。在我的联系人页面中,我无法使用此代码发送邮件。单击“提交”按钮后,将显示一个空白页 php mail()函数有时会出现意外行为
根据我和其他人的经验,mail()函数不是特别可预测的,也不是特别有用
非常值得注意的是,mail()函数在Linux和Windows>服务器之间的行为完全不同。在linux上它使用sendmail,但在Windows上它使用SMTP
为了让mail()函数在所有php.ini上都能正常工作,需要配置>正确,指定sendmail或SMTP服务器的位置
mail()的问题在于,它“试图”将事情简化到这样一个程度:由于糟糕的界面设计,它实际上>使事情变得更加复杂。Swift Mailer的开发人员已经>付出了很大的努力,使邮件传输具有合理的>一致性
我建议您使用库发送邮件,这是非常强大的。您正在使用localhost吗?一个空白页可能是由于抛出错误而导致的,但是错误报告是关闭的。您启用了吗?我正在使用localhost。在localhost中,它应该会向我们显示一条错误消息。