2012-12-14 59 views
2

我一直在嘗試爲我的網站做一個電子郵件確認。人們可以註冊沒有問題,並且所有內容都註冊到數據庫中,但不會發送電子郵件。我正常使用它,它給了我關於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"; 
} 
?> 
+1

檢查您的日誌文件是否有錯誤。 PHP的'mail()'函數並不保證郵件發送,只是它被接受發送。 – j08691

+0

btw爲了發送HTML電子郵件,您需要定義MIME-TYPE和Content-type。此頁面底部的示例:http://www.w3schools.com/php/func_mail_mail.asp – christopher

+0

您不必包含MIME-TYPE和Content-Type。無論如何它會發送。 @ user1868065如果它是你的服務器,檢查/ var/log/maillog,看看裏面是否有錯誤。如果您無法訪問服務器,可嘗試使用SwiftMailer並使用IMAP等方式通過另一臺郵件服務器進行連接。 – ChrisG

回答

0

1-嘗試使用此郵件功能。

2 - 寫「從價值」爲有效的電子郵件與你的域名,如:若步驟不起作用,請致電您的託管我猜郵件阻止他們()函數[email protected]

3-。

function send_mail($to,$from,$subject,$msg){ 
     // message 
     $message = ' 
     <html> 
     <head> 
      <title>Message</title> 
     </head> 
     <body dir="rtl"> 
     <p align="right">' 
     . $msg . 
     '</p> 
     <br> 

     </p> 
     </body> 
     </html> 
     '; 

     // To send HTML mail, the Content-type header must be set 
     $headers = 'MIME-Version: 1.0' . "\n"; 
     $headers .= 'Content-type: text/html; charset=utf-8' . "\n"; 

     // Additional heade rs 
     $headers .= "From: ".$from . "\n"; 
     //$headers .= 'Bcc: [email protected]' . "\n"; 

     // Mail it 
     return mail($to, '=?windows-1256?B?'.base64_encode($subject).'?=', $message, $headers); 
    } 
+0

我其實只是嘗試PHP郵件,它原來也是一個PHP郵件擴展名已關閉,並嘗試使用Phpmailer風格,而且效果很好,謝謝你的幫助! – user1868065

0

我建議使用Gmail帳戶發送電子郵件,這是爲我設置的最快的一個。 (只是谷歌'發送PHP的Gmail郵件')。另外,不要忘記檢查垃圾郵件文件夾。