SMTP电子邮件不发送

时间:2014-11-08 23:20:28

标签: php smtp

我正在尝试通过smtp发送电子邮件,但不幸的是,它没有被发送。似乎没有错误。我在哪里有错?

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "mail.site.org"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "info@site.org";  // SMTP username
$mail->Password = "123456"; // SMTP password

$mail->From     = "info@bosiadbodrum.org"; // smtp kullanıcı adınız ile aynı olmalı
$mail->Fromname = "giden ismi";
$mail->AddAddress("info@alanadi.com","Ornek Isim");
$mail->Subject  =  $_POST['baslik'];
$mail->Body     =  implode("    ",$_POST);

if(!$mail->Send())
{
   echo "Mail couldnt send <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Mail sent";

1 个答案:

答案 0 :(得分:1)

试试这个,以获取错误:

require("class.phpmailer.php");

$mail = new PHPMailer(true);
try {
$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "mail.site.org"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "info@site.org";  // SMTP username
$mail->Password = "123456"; // SMTP password

$mail->From     = "info@bosiadbodrum.org"; // smtp kullanıcı adınız ile aynı olmalı
$mail->Fromname = "giden ismi";
$mail->AddAddress("info@alanadi.com","Ornek Isim");
$mail->Subject  =  $_POST['baslik'];
$mail->Body     =  implode("    ",$_POST);
$mail->Send();
echo "Message Sent OK\n";
} 
catch (phpmailerException $e) {
  echo $e->errorMessage();
} 
catch (Exception $e) {
  echo $e->getMessage();
}