我一直在嘗試爲我的網站做一個電子郵件確認。人們可以註冊沒有問題,並且所有內容都註冊到數據庫中,但不會發送電子郵件。我正常使用它,它給了我關於SMTP服務器的一些錯誤,所以有人說我應該嘗試SurgeMailer。我下載了它,現在電子郵件實際上說他們發送了,但電子郵件從未收到它們。任何幫助將是偉大的!下面是發送電子郵件的代碼。通過php發送郵件不工作
/*Send Email here*/
$to=$Email;
$subject="Newgenstudios Account Confirmation";
/*From*/
$header="From:Newgenstudios <[email protected]>";
/* Your message */ /*Not Finished */
$message = "<h3>Welcome to the site ".ucfirst(strtolower($First_Name))."!</h3>
<p>To complete your account registration, you must activate your account. Click on the link below or paste it into the URL to activate your account.</p>
<p><a href='http://localhost/confirmation.php?passkey=$confirm_code'>Activate Now!</a </p>
<p>Once your account has been activated, you may log in at anytime using the information you supplied below:<br />
<strong>Email: </strong>$Email<br />
<strong>Password: </strong>$Password</p>
<p>Other Information:</p>
<strong>Name: </strong>$First_Name<br />
<strong>Phone: </strong>$Phone<br />
<p>Thank you for registering and see you on the site!</p>
<p>Did you not register? Then please disregard this message.</p>";
/* Send Email */
$sentmail = mail($to,$subject,$message,$header);
}
/*If not found*/
else {
echo "Not found your email in our database";
}
/* email succesfully sent */
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>
檢查您的日誌文件是否有錯誤。 PHP的'mail()'函數並不保證郵件發送,只是它被接受發送。 – j08691
btw爲了發送HTML電子郵件,您需要定義MIME-TYPE和Content-type。此頁面底部的示例:http://www.w3schools.com/php/func_mail_mail.asp – christopher
您不必包含MIME-TYPE和Content-Type。無論如何它會發送。 @ user1868065如果它是你的服務器,檢查/ var/log/maillog,看看裏面是否有錯誤。如果您無法訪問服務器,可嘗試使用SwiftMailer並使用IMAP等方式通過另一臺郵件服務器進行連接。 – ChrisG