简体   繁体   中英

SMTP -> ERROR: Failed to connect to server: The following From address failed: : Called Mail() without being connected Mailer Error

I have been stuck here for almost a week. I actually followed the steps in the tutorials, but had no luck. I downloaded this phpmailer and got version 5.4.2. the code below is an example of this downloaded phpmailer but it does not work for me. I have already configure the sendmail and php.ini. I have also enable some extensions such as php openssl and phpsocket php smtp and the apache module. I hope someone will help me with this problem,I hope. Here is my code below:

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>

<?php

error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = "dasdf";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "gg@gmail.com";  // GMAIL username
$mail->Password   = "ggg";            // GMAIL password

$mail->SetFrom('gg@gmail.com', 'jj');

$mail->AddReplyTo("gg@gmail.com","jj");

$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "espadadave@yahoo.com";
$mail->AddAddress($address, "Dave");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

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

?>

</body>
</html>

That version of PHPMailer is very out of date (last updated February 2013); it has been superseded by https://github.com/PHPMailer/PHPMailer

Before anything else, you should upgrade to the latest version; There's a good chance you're trying to work around a bug that's already been fixed.

You'll find the usage is almost identical; check the example on the GitHub page for the obvious differences in the current version.

You should also enable SMTP debugging by adding

$mail->SMTPDebug = 3;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM