我试图使用php邮件程序与symfony 2
public function sendMailAction($email){
$user = $this->getUser();
$UserMail = $user->getEmail();
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = 'myGmail@gmail.com';
$mail->Password = '********';
$mail->setFrom('myGmail@gmail.com', 'Mailer');
$mail->addAddress($email, 'A Name');
$mail->isHtml(true);
$mail->Subject = 'PHPmailer test';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
if(!$mail->send()){
return new JsonResponse($mail->ErrorInfo);
} else {
return new JsonResponse("mail envoyé");
}
}
我遵循所有github教程,尝试更改端口(ssl为465,tsl为587),并在stackoverflow中花费大量时间来创建一个awnser,但在最后我总是有同样的错误&#34 ; SMTP错误:无法连接到服务器&#34;。 THX