我想從下面的PHP代碼的xampp服務器發送電子郵件。 PHP代碼似乎工作正常,因爲它提供了所有成功和錯誤消息,但我沒有收到我提供的電子郵件中的任何郵件。通過郵件()函數從本地服務器發送電子郵件
<?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
和c:\xampp\sendmail\sendmail.ini
其實我有兩個php.ini的開發和生產。我更改了php-ini-development
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=gmailpassword
[email protected]
如果垃圾郵件文件夾中存在垃圾郵件,是否已檢查過您的電子郵件? (從php'mail()'函數發送的電子郵件通常會被標記爲垃圾郵件 - 如果您想避免這種情況,請查看SendGrid或Mailgun) – Howl
請查看此文章http://php.codeindepth.com/php-發送郵件/ – Cody