2016-05-06 27 views
0

ローカルホストからmail-idにメールを送信します。私はphp-Mailerを使用しています。しかし、SMTP接続が失敗したと言います。誰でも私を助けてくれる?私のコードは以下の通りです:あなたは、SMTPの詳細そのバウンス(再起動)した後 phpメーラーでsmtp接続に失敗しました

一度あなたのapacheを与える必要があり

<?php 

    require_once('class.phpmailer.php'); 


    $mail = new PHPMailer(); 

    $body='hai'; 
    $address='[email protected]'; 
    $name='hey'; 

    $mail->IsSMTP(); 
    $mail->SMTPAuth = true; 
    $mail->Host = "localhost"; 
    $mail->Port = 25; 
    $mail->Username = "#@#@#@#@-####[email protected]@@@-#####[email protected]#@#@#@#@#@#"; 
    $mail->Password = "#@#@#@#@-####[email protected]@@@-#####[email protected]#@#@#@#@#@#"; 

    $mail->SetFrom('[email protected]','Web App'); 
    $mail->Subject = "A Transactional Email From Web App"; 
    $mail->MsgHTML($body); 
    $mail->AddAddress($address, $name); 



    if($mail->Send()) { 
     echo "Message sent!"; 
    } else { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
    } 

    ?> 
+0

ローカルからメールを送信することはできません。他のsmtpの詳細を使用する Gmailのようなもの smtp.gmail.com ポート465 ローカルから送信する –

+0

@NirojAdhikary私もそれを試していました。しかし、動作していない –

+0

私はposted.But私はあなたがmailgun APIを使用することをお勧めします新しい答えを確認 –

答えて

0

<?php 
require dirname(__FILE__) .'/library/PHPMailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer(true); 

//$mail->SMTPDebug = 2; // error mode       
    //$mail->SMTPDebug = 3; // error mode       

$mail->isSMTP();          
$mail->Host = 'mail.xxx.com'; 
$mail->SMTPAuth = true;        
$mail->Username = '[email protected]';    
    $mail->Password = 'XXXXX';       
//$mail->SMTPSecure = 'None';      
$mail->Port = 25;         

$mail->setFrom('[email protected]', 'XXXXXX'); 

//for sending mail 
$mail->addAddress($username);  // Add a recipient 

$mail->isHTML(true);  // Set email format to  HTML 

$mail->Subject = 'HAI'; 
    $mail->Body = '<br> <br> 
      <html><body> <div><div><u><h3>HAI </h3></u></div><div><p>This email has been sent for testing</p><p>xxx<b>xx</b></p><p>xx<b>xx</b></p></div>  </body></html>'; 
    $mail->AltBody = 'Unable to display the mail'; 

    if(!$mail->send()) 
    { 
    echo 'Message could not be sent.'; 
     echo 'Mailer Error: ' . $mail->ErrorInfo; 

     } 
     else 
     { 
     echo 'Message has been sent'; 

     } 
     ?> 
+0

$ mail-> SMTPDebug = 2;この行のコメントを外してエラーを知る – JYoThI

+0

ok mam i ll tr​​y –

-1
$mail = new PHPMailer; 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->SMTPAuth=true; 
//$mail->SMTPDebug=2; 
$mail->Host='smtp.gmail.com'; // SMTP server 
$mail->Username ='[email protected]'; 
$mail->Password ='...'; 
$mail->SMTPSecure='ssl'; 
$mail->Port=465; 
$mail->isHTML(true); 
+1

あなたの答えに説明を追加する必要があります –

-1

PHP mailer docs example

<?php 
require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]le.com'); 

$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 
+0

盲目的に回答を投稿するだけではありません - あなたの回答が質問に記載されている特定の問題を解決する理由を説明してください。 – Synchro

関連する問題