我正在創建PHP類來發送電子郵件。問題是由於某些原因郵件沒有發送。有人知道問題在哪裏嗎?PHPMailer無法發送電子郵件
我正在這對XAMPP
下面是代碼:
include_once "class.sendMAIL.php";
$sendActivation = new sendMAIL();
$body="http://$_SERVER[HTTP_HOST]/activation.php?id=$activationCode";
if ($sendActivation->sendActivationEmail($name, $email,$body))
{
echo "MAIL SENT";
}
else {
echo "ERROR IN SENDING";
}
郵件類:
require 'PHPMailerAutoload.php';
class sendMAIL {
private $sendEmail;
public function __construct() {
$this->sendEmail = new PHPMailer();
$this->sendEmail->isSMTP(); // Set mailer to use SMTP
$this->sendEmail->Host = ' smtp.gmail.com'; // Specify main and backup SMTP servers
$this->sendEmail->SMTPAuth = true; // Enable SMTP authentication
$this->sendEmail->Username = '[email protected]'; // SMTP username
$this->sendEmail->Password = 'mypassword'; // SMTP password
$this->sendEmail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$this->sendEmail->port ="465";
$this->sendEmail->From = "";
//$this->sendEmail->FromName = $name;
$this->sendEmail->isHTML(true);
}
public function sendActivationEmail($name, $email, $link) {
$this->sendEmail->AddAddress($email);
$this->sendEmail->Subject="Aktivacija";
$body="Follow this link to activate your account: <a href='$link' />LINK</a>";
$this->sendEmail->MsgHTML($body);
if($this->sendEmail->send()) {
return TRUE;
}
else {
return FALSE;
}
}
}
THIS IS錯誤我得到了什麼當我調試的問題:
You must provide at least one recipient email address.
謝謝到@paulgv我修正了錯誤,但現在我得到了這個錯誤:
SMTP connect() failed
有人知道問題在哪裏嗎?
編輯:問題導致gmail。 Gmail阻止我的網絡應用程序訪問我的電子郵件。
你怎麼知道它不發送? (不接收不一樣不發送) – 2014-12-04 21:41:08
所以你得到虛假回來?那麼你應該檢查'$ this-> sendEmail-> ErrorInfo'的細節。和/或看看你的郵件服務器的日誌,看看/爲什麼郵件被拒絕 – 2014-12-04 21:42:02
我試過......我調試,如果郵件從類發送調用sendMAIL類和輸出是假的 – jureispro 2014-12-04 21:42:09