HostMonster網站程式一般無法發送郵件,因為連接埠25阻塞了。
許多ISP屏蔽了連接埠25的使用,而該連接埠是用來發送郵件的。他們這樣做是為了減少垃圾郵件的發送量。所有通過Internet發送的 e-mail 都要通過連接埠25, 該通道用來進行e-mail 用戶端和 e-mail伺服器之間的通訊。
雖然連接埠25屏蔽很可能成為一個工業標準,但是過濾器會給 e-mail伺服器帶來麻煩,導致正常的郵件被當成垃圾郵件處理。
連接埠25屏蔽可以協助網路服務供應商們阻止垃圾資訊在他們的網路上的傳播,但是這樣的話,會給那些有需求使用e-mail伺服器發送郵件的人帶來麻煩,這些伺服器不僅僅是他們自己的ISP提供的。
屏蔽連接埠25的網路服務供應商要求使用他們的SMTP伺服器,而不是遠程SMTP伺服器或自己電腦上啟動並執行SMTP伺服器。
還好的是,HostMonster開放了26連接埠給SMTP伺服器。
我們先到 CPanel -> Email Accounts,建立一個郵件賬戶。
然後到 CPanel -> webmail -> Configure Mail Client,可以得到下面配置資訊:
Manual SettingsMail Server Username: bkjia+bkjia.comIncoming Mail Server: mail.bkjia.comIncoming Mail Server: (SSL) host.hostmonster.comOutgoing Mail Server: mail.bkjia.com (server requires authentication) port 26Outgoing Mail Server: (SSL) host.hostmonster.com (server requires authentication) port 465Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS)Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS)
提示:smtp伺服器是 mail.yourdomain.com,連接埠是26,帳號是你的郵箱的完整地址 xxxx@xxx.com,密碼就是你的郵箱密碼。按照提示設定好,就可以使用hostmonster主機提供的SMTP服務了。
樣本程式如下,程式使用了PHPmailer庫:
function mailto($nickname, $address){$this->load->helper('url');date_default_timezone_set('PRC'); include_once("application/controllers/class.phpmailer.php");$mail = new PHPMailer(); // defaults to using php "mail()"$mail->IsSMTP(); // telling the class to use SMTP$mail->IsHTML(true);$mail->Host = "mail.bkjia.com"; // SMTP server$mail->SMTPDebug = 1; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only$mail->SMTPAuth = true; // enable SMTP authentication$mail->Host = "mail.bkjia.com"; // sets the SMTP server$mail->Port = 26; // set the SMTP port for the GMAIL server$mail->Username = "bkjia@bkjia.com"; // SMTP account username$mail->Password = "********"; // SMTP account password$mail->CharSet="utf-8"; //$body = file_get_contents('application/views/nmra/register.html');//$body = preg_replace('/\\\\/','', $body); //Strip backslashes$body = '';$body .= '';//$body .= '';$body .= ''.$nickname.',您好。
';$body .= '請點擊以下連結驗證您的郵箱,請注意網域名稱為bkjia.com:'.base_url().'accounts/activation/';$body .= '順祝工作學習愉快,生活舒心。
';$body .= '';//echo $body;$mail->AddReplyTo("bkjia@163.com","Gonn");$mail->SetFrom('bkjia@163.com', 'Gonn');$mail->AddReplyTo("bkjia@163.com","Gonn");$mail->AddAddress($address, $nickname);$subject = "收到來自幫客之家的郵件";$mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";// optional, comment out and test$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; $mail->MsgHTML($body);//$mail->AddAttachment("images/phpmailer.gif"); // attachment//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachmentif(!$mail->Send()) {//echo "Mailer Error: " . $mail->ErrorInfo;} else {//echo "Message sent!";}}
OK,現在網站程式就能發郵件了。但是並非所有郵箱都能收到,這裡測試的話,163,gmail等都能正常收到,而qq則收不到。如果你有更好的方法,請告知我,感謝。
http://www.bkjia.com/PHPjc/752343.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/752343.htmlTechArticleHostMonster網站程式一般無法發送郵件,因為連接埠25阻塞了。 許多ISP屏蔽了連接埠25的使用,而該連接埠是用來發送郵件的。他們這樣做是為了減少...