我有这个简单的php邮件功能
$to = "munucom@mail.ru";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: munucom@mail.ru" . "\r\n" .
"CC: munucom@mail.ru";
if(mail($to,$subject,$txt,$headers)){
echo "done";
}
它已经完成,但当我查看我的电子邮件时,什么也没有。甚至在垃圾邮件部分
答案 0 :(得分:0)
使用PHPMailer库。它比使用邮件本机功能更好,因为在PHPMailer中您可以使用用户身份验证来避免将电子邮件发送到垃圾邮件。您可以使用此库而无需配置邮件服务器。它更容易调试。您可以在此链接https://github.com/PHPMailer/PHPMailer
下载查看示例:
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 587; // SMTP port
$mail->Username = "yourusername@gmail.com"; // username
$mail->Password = "yourpassword"; // password
$mail->SetFrom('user@gmail.com', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "test@test.com";
$mail->AddAddress($address, "Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}