快速邮件不在现场工作,但在当地工作为什么?

时间:2016-04-06 10:57:02

标签: php codeigniter swiftmailer

// Create the mail transport configuration
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
    ->setUsername(PASUPUKUMKUMA_EMAIL)
    ->setPassword(PASUPUKUMKUMA_PASS);


// Create the message
$message = Swift_Message::newInstance()
    ->setTo(array($email => $name))
    ->setSubject("Registration Success !")
    ->setBody('You have Registered Successfully ! Thank You For Registering With Us.Click the link to confirm your account <a href='.site_url().'/main/confirm/'.$name.'/'.$ran.'>confirm here</a>', 'text/html')
    ->setFrom(PASUPUKUMKUMA_EMAIL,EMAIL_FROM_NAME);

// Send the email
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);

这是我通过swift邮件发送电子邮件的代码当我在本地发送邮件时,一切都很完美我可以成功发送邮件。

当来到具有相同代码的实时网站时,无法发送邮件并显示错误:

Connection could not be established with host smtp.gmail.com..

1 个答案:

答案 0 :(得分:0)

https://www.google.com/settings/security/lesssecureapps

为您正在使用的帐户启用它。希望它会有所帮助。