使用PHPMailer的庫nothing.Even。這比使用郵件本機功能要好,因爲在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 = "[email protected]"; // username
$mail->Password = "yourpassword"; // password
$mail->SetFrom('[email protected]', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "[email protected]";
$mail->AddAddress($address, "Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
這是在本地主機或託管的服務器上? – Qirel
Localhost @Qirel –
郵件功能在localhost中不起作用 –