我一直在尝试使用PHPMailer从我的本地主机发送电子邮件,但我无法修复此错误
SMTP connect()失败.
我知道有这种错误的建议,但我试过的似乎对我有用.这是我的设置
$mail = new PHPMailer();
$mail->IsSMTP(); // we are going to use SMTP
$mail->Host = 'smtp.gmail.com'; // setting GMail as our SMTP server
$mail->SMTPAuth = true; // enabled SMTP authentication
$mail->Username = 'mygamil'; // user email address
$mail->Password = "mypassword"; // password in GMail
$mail->SMTPSecure = "tls"; // prefix for secure protocol to connect to the server
$mail->SetFrom($this->session->userdata('email'), $this->session->userdata('username')); //Who is sending the email
$mail->AddReplyTo("someone@domain.com",$this->session->userdata('username')); //email address that receives the response
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
$destino = "someone@domain.com"; // Who is addressed the email to
$mail->AddAddress($destino, "Sender name");
$mail->AddAttachment($file_path); // some attached files/
if($mail->Send() ==TRUE){
redirect('app/send/'.$this->uri->segment(3).'/succeeded ');
}
else
{
//show an error email failed erroers
$email_error = array('email_error'=>$mail->ErrorInfo);
}
我尝试过端口587和465它们似乎都没有工作,但当我telnet到任一端口我得到连接没有错误
我在php.ini中启用了openssll.dill
我已经在我的Mac和Ubuntu 12.04中的MAMP中尝试了这个设置,但我仍然得到相同的错误
任何输入将提前感谢
解决方法:
您的连接配置中需要完整的电子邮件地址:
$mail->Username = 'username@gmail.com';
如果使用TLS安全协议,您需要使用:
$mail->SMTPSecure = "tls";
$mail-> Port = 587;
...
或SSL(已弃用状态):
$mail->SMTPSecure = "ssl";
$mail-> Port = 465;
...