2011-10-20 16 views
0

私はHTML形式の電子メールを作成しました。私はPHP(mail();関数を使用して)を送信する予定でした。しかし、私がこれをしたとき、メールはhotmailとgmailアカウントに届かなかった。私はちょっと調べてみて、人々はPHPmailerの使用を提案しました。誰かがphpmailerで私を助けてくれますか?

PHPmailerをダウンロードし、私のサーバーにインストールしました。ここまでは順調ですね。私はいくつかの問題を持って

<?php 
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\phpmailer.inc.php'); 
set_include_path('.:c:\domains\mydomain\wwwroot\phpmailer\smtp.inc.php'); 

require("phpmailer.inc.php"); 


$mail = new PHPMailer(); 

$mail->IsHTML(true); 
$mail->From  = "[email protected]"; 
$mail->AddAddress("[email protected]"); 

$mail->Subject = "An HTML Message"; 
$mail->Body  = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!"; 

if($mail->Send()) { 
    echo 'Message is sent'; 

} else { 
    echo 'Message was not sent..'; 
echo 'Mailer error: ' . $mail->ErrorInfo; 
} 
?> 

:しかし、今、私は次のコードを持っているの出力は、電子メールが送信されていない私に指示

  • を、それがあります。
  • 私は2つのサブジェクトを取得します
  • html(テーブルのような)を追加すると、それでもホットメール(おそらくgmail)によって拒否されます。

また、SMTP機能があります。この機能の使い方は?自分のSMTPを書き留める必要がありますか?

誰かが私を助けてくれたら大変うれしいですね。

編集:私は別のプロジェクトでphpmailerのを使用

class SMTP { 
    var $SMTP_PORT = 25; # the default SMTP PORT 
    var $CRLF = "\r\n"; # CRLF pair 

    var $smtp_conn;  # the socket to the server 
    var $error;   # error if any on the last call 
    var $helo_rply;  # the reply the server sent to us for HELO 

    var $do_debug;  # the level of debug to perform 

    /* 
    * SMTP() 
    * 
    * Initialize the class so that the data is in a known state. 
    */ 
    function SMTP() { 
     $this->smtp_conn = 0; 
     $this->error = null; 
     $this->helo_rply = null; 

     $this->do_debug = 0; 
    } 
+0

サーバによってあなたは 'リモートserver'を意味していますか? set_inclide_pathにローカルサーバーパスが含まれていますか? PHPMailerはあなたのローカルサーバでは動作しません –

+0

Nah、サーバーで私は自分のウェブサイトを意味しました。申し訳ありません – Frank

答えて

0

私はもちろんphpmailerのは、それをサポートしている、あなたはSMTP経由でメールを送信することをお勧め:

$mail = new PHPMailer(); 
$mail->IsSMTP();  // send via SMTP 
$mail->Host = "smtp.gmail.com" //(or the smtp server you use) 
$mail->Port = "465" //(gmail uses secure smtp so that runs on port 465) 
$mail->SMTPAuth = "true" //we need to autenticate to the server 
$mail->SMTPSecure = "ssl" //we use ssl to protected the flow of info 
$mail->Username = "[email protected]" //account 
$mail->Password = "password" //password 


//build the message 
$mail->IsHTML(true); 
$mail->From  = "[email protected]"; 
$mail->AddAddress("[email protected]"); //who receives the mail 
$mail->Subject = "An HTML Message"; 
$mail->Body  = "Hello, <b>my friend</b>! \n\n This message uses HTML entities!"; 

if($mail->Send()) { 
    echo 'Message is sent'; 

} 
else { 
    echo 'Message was not sent..'; 
echo 'Mailer error: ' . $mail->ErrorInfo; 
} 
+0

ありがとうございます。 1つの質問:SMTPを使用している場合、既存のメールアドレスのみを使用できますか? mail();存在しない電子メールアドレスを使用することもできます.... – Frank

+0

。ただし、送信元アドレスを設定するときにSMTPを使用する場合でも、smtp経由で接続するアドレスとは異なるアドレスを指定することができます:$ mail-> From = "[email protected]"; –

+0

ダム、私はそれを働かせることはできません。私はこのエラーが表示されます:致命的なエラー:C:\ path \でクラスSMTPを再宣言できません。\ my \ domain \ smtp.inc.php 26行目のコードを元の投稿で編集してください。 – Frank

関連する問題