メール機能をインスタンス化できませんでした。なぜこのエラーが発生するのか質問する

メール機能をインスタンス化できませんでした。なぜこのエラーが発生するのか質問する

PHPMailer 経由でメールを送信しようとすると、このエラー メッセージが表示されます。コードは次のとおりです。

<?
require("phpmailer/class.phpmailer.php"); // First we require the PHPMailer libary in our script
$mail = new PHPMailer(); // Next we create a new object of the PHPMailer called $mail
$mail->From = "[email protected]";
$mail->FromName = "Rajasekar";
$mail->AddAddress("[email protected]"); // This is the adress to witch the email has to be send.
$mail->Subject = "First PHP Email message"; // This is the subject  of the email message.
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHP."; // This is the actual email message
if(!$mail->Send()) // Now we send the email and check if it was send or not.
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
   echo 'Message has been sent.';
}
?>

ベストアンサー1

Ubuntu(少なくとも12.04)では、sendmailはデフォルトではインストールされていないようです。次のコマンドを使用してインストールする必要があります。sudo apt-get install sendmail-bin

また、上記のように適切な権限を設定する必要がある場合もあります。

おすすめ記事