我正在尝试使用以下php代码从xampp服务器发送电子邮件。 Php代码似乎工作正常,因为它提供了所有成功和错误消息,但我没有收到我在表单中提供的电子邮件的任何邮件。
<!-- Core plugins -->
<gap:plugin name="org.apache.cordova.battery-status" />
<gap:plugin name="org.apache.cordova.camera" />
<gap:plugin name="org.apache.cordova.media-capture" />
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.contacts" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.device-motion" />
<gap:plugin name="org.apache.cordova.device-orientation" />
<gap:plugin name="org.apache.cordova.dialogs" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.file-transfer" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.globalization" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.media" />
<gap:plugin name="org.apache.cordova.network-information" />
<gap:plugin name="org.apache.cordova.splashscreen" />
<gap:plugin name="org.apache.cordova.vibration" />
我还对<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {// Validate email address
$message = "Invalid email address please type a valid email!";
}
else
{
$query = $con->prepare("SELECT username FROM members where email=:email");
$query->execute(array(':email'=>$email));
$row = $query->fetch(PDO::FETCH_ASSOC);
if($query->rowCount() == 1) {
$encrypt = md5(1290*3+$row['username']);
$message = "Your password reset link has been send to your e-mail address. Check your mail and click on the link therein.";
$to=$email;
$subject="Password Recovery";
$from = 'mydemo.com';
$body='Hi, <br/> <br/>Your username is '.$row['username'].' <br><br>Click here to reset your password http://localhost/mydemo/reset.php?encrypt='.$encrypt.' <br/> <br/>--<br>';
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,$body,$headers);
}
else
{
$message = "Account not found please enter email you provided during sign up!";
}
}
}
<form action="" method="POST">
<legend>Forgot your password!</legend>
<input type="email" name="email" id="email" required="required" maxlength="35" placeholder="Enter your email here..."/>
<input type="submit" name="submit" id="submit" value="Submit"/>
</form>
<div id="message"><?php echo $message; ?></div>
和C:\xampp\php\php.ini
进行了以下更改,实际上我有两个php.ini开发和生产。我对c:\xampp\sendmail\sendmail.ini
php-ini-development
答案 0 :(得分:1)
if (!mail($to,$subject,$body,$headers)) {
/*Here you can log error*/
print_r(error_get_last());
}
答案 1 :(得分:0)
您不知道它是否正常工作,因为您没有检查函数mail()的结果。如果
,请添加一个if (false === mail($to,$subject,$body,$headers)) {
$message = "Mail was not sent";
}
来自手册:
如果邮件成功接受传递,则返回TRUE,否则返回FALSE。
重要的是要注意,仅仅因为邮件已被接受发送,并不意味着邮件实际上会到达目的地。