使用php发送电子邮件时出错

时间:2016-05-03 11:43:08

标签: php

SMTP - >错误:无法连接到服务器:尝试以其访问权限禁止的方式访问套接字。 (10013)以下发件人地址失败:info@gmail.com:未连接称为Mail()

    $mail = new PHPMailer();                
    $mail->IsSMTP(); 
    $mail->SMTPDebug  = 1; 
    $mail->SMTPAuth   = true; 
    $mail->SMTPSecure = "tls";  
    $mail->Host = "smtp.gmail.com"; 
    $mail->Port = 587; 
    $mail->Username = "gmail.com"; 
    $mail->Password = "password";        
    $mail->From = "info@gmail.com";
    $mail->FromName = "name.com";
    $mail->Subject = "Register";
    $mail->MsgHTML($userMsg);


    $mail->AddAddress("email address", "name");
    //$mail->AddAddress($rowUser['user_email'], $rowUser['user_name']);
    $mail->send();
    $mail->ClearAllRecipients();

1 个答案:

答案 0 :(得分:0)

TLS是正确的,您可以尝试SSL,将端口更改为465.检查您的凭据。是屏幕上的用户名" gmail.com"?

试试这个:

$mail = new PHPMailer(); 
$mail->IsSMTP(); // enable SMTP
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "yourname@gmail.com";
$mail->Password = "yourpassword";
$mail->SetFrom("example@gmail.com");
$mail->Subject = $subject;
$mail->Body =$body;
$mail->AddAddress($email);
if(!$mail->Send())
{
    return FALSE;
}