0

こんにちは、メールの送信に phpMailer を使用しています。サーバー上では正常に動作していますが、ローカル マシン (localhost) からメールを送信しようとすると、エラーが発生します。GMAIL smtp を使用しています

<?
require("lib/class.phpmailer.php"); 
$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->SMTPAuth = true;
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465; 
$mail->Username = "XXX@XXX.com";  // SMTP username
$mail->Password = "XXXXXXX"; // SMTP password
$mail->From = $email; 
$mail->AddAddress("XXXXXX@XXX.com", "XX XX XX");
$mail->WordWrap = 50;
$mail->IsHTML(true); 
$mail->Subject = "You have received feedback from your website!";
$mail->Body    = $message;
$mail->AltBody = $message; 
if(!$mail->Send())
 {
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
 }

 }
 ?>

エラーは

SMTP Error: Could not connect to SMTP host. Message could not be sent.

Mailer Error: SMTP Error: Could not connect to SMTP host.

私のサーバーでは問題なく動作しています。

4

1 に答える 1

1

さて、私はローカルでそれを手に入れました ここに私が使用したコードがあります

<?php
    require("phpmailer/class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->IsSMTP(); // send via SMTP
    IsSMTP(); // send via SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "username@gmail.com"; // SMTP username
    $mail->Password = "password"; // SMTP password
    $webmaster_email = "username@doamin.com"; //Reply to this email ID
    $email="username@domain.com"; // Recipients email ID
    $name="name"; // Recipient's name
    $mail->From = $webmaster_email;
    $mail->FromName = "Webmaster";
    $mail->AddAddress($email,$name);
    $mail->AddReplyTo($webmaster_email,"Webmaster");
    $mail->WordWrap = 50; // set word wrap
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = "This is the subject";
    $mail->Body = "This is the HTML BODY "; //HTML Body
    $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
    if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }
    ?>
于 2012-09-24T17:10:43.790 に答える